N
N
Nikolay Baranenko2016-06-15 21:56:42
Java
Nikolay Baranenko, 2016-06-15 21:56:42

What is the correct way to connect via JDBC to SAS MetaDataServer?

Hello.

I'm trying to connect to SAS MetaDataServer and I'm getting an error

java.sql.SQLException: Unable to establish a connection: Unable to return workspace. The client has connected to a SAS (9.2) Metadata Server (v1.0) when it intended to connect to a SAS Workspace Server.


<%
    Connection connection;
    Properties props;
    Statement statement;

  /* SAS datasets can be queried with a SQL statement itself */

    String queryString = "SELECT username FROM MySasLib.users1 t1";

    ResultSet result;
    String id;
    String name;
    int i=1;
    try {
        // CONNECT TO THE SERVER BY USING A CONNECTION PROPERTY LIST

        try
        {
            Class.forName("com.sas.rio.MVADriver");
        } catch (ClassNotFoundException e)
        {
            System.out.println(e.getMessage());
        }

        props = new Properties();
        props.setProperty("user", "user1");
        props.setProperty("password", "pwd1");
        props.setProperty("librefs", "mySasLib '/sas/dwh/user1/';");

   /* SAS libref and library name */

        //ACCESS DATA

             connection = DriverManager.getConnection("jdbc:sasiom://server.inside.my.ru:8000", props);

        statement = connection.createStatement();
        result = statement.executeQuery(queryString);
        ResultSetMetaData rsmd = result.getMetaData();
        int colCount = rsmd.getColumnCount();
        out.println("<TABLE border='1'>");
        out.println("<TR>");
        for (i = 1; i <= colCount; ++i) {
            out.println("<TH>" + rsmd.getColumnLabel(i) + "</TH>");
        }
        out.println("</TR>");
        String val = null;
        while (result.next()) {
            out.print("<TR>");
            for (i = 1; i <= colCount; ++i) {
                val = result.getString(i);
                if (result.wasNull()) {
                    val = nbsp;
                }
                out.print("<TD>" + val + "</TD>");
            }
            out.println("</TR>");
        }
        out.println("</TABLE>");
        statement.close();
        connection.close();
    } catch (Exception e) {
        out.println("error " + e);
    }
%>


Tell me how to connect correctly?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question