The following sample
code passes a libref property on the JDBC URL to a SAS Workspace Server.
Here are the scenario details:
-
Because you are accessing a workspace
server, you must use the IOM driver. The driver class name for the
IOM driver is com.sas.rio.MVADriver.
-
The host name for the server is
c123.na.abc.com, and the port number is 5671.
-
The librefs connection property
is used to assign a SAS library, which is
c:\sasdata
. The first backslash
is used to escape the backslash in the actual location.
-
Because the server is password-protected,
you specify values for the user and password connection properties.
import java.sql.*;
public class AccessBase
{
public static void main(String argv[])
{
Connection connection;
int i;
Statement statement;
String queryString = "SELECT sup_id, sup_name " +
"FROM mySASLib.suppliers ORDER BY sup_name";
ResultSet result;
double id;
String name;
try{
//CONNECT TO THE SERVER BY USING A JDBC URL
Class.forName("com.sas.rio.MVADriver");
String user = "jdoe";
String password = "4ht8d";
connection = DriverManager.getConnection(
"jdbc:sasiom://c123.na.abc.com:5671?" +
"librefs=MySasLib 'c:\\sasdata'",
user, password);
//ACCESS DATA
statement = connection.createStatement();
result = statement.executeQuery(queryString);
while (result.next()) {
id = result.getDouble(1);
name = result.getString(2);
System.out.println(id + " " + name);
}
statement.close();
connection.close();
}
catch(Exception e){
System.out.println("error " + e);
}
}
}