Sample 26049: How to Connect to a SAS® Workspace Server with JDBC
Overview
This sample uses the SAS® Integration Technologies MVADriver class to connect to a SAS Workspace Server. This JDBC driver is part of the Foundation Services API.
To use the JSP file in this sample, you will need the Foundation Services JAR files in the WEB-INF/lib directory of your Web application.
Additional Documentation
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
The JSP code below demonstrates how to assign a library and submit a simple query to a SAS Workspace Server using the MVADriver. The code then writes the ResultSet out to a simple HTML table.
<%@ page import="java.sql.*"%>
<%
Connection con = null;
Statement stmt = null;
try{
Class.forName("com.sas.rio.MVADriver");
String url = "jdbc:sasiom://myServer.test.com:8591";
java.util.Properties p = new java.util.Properties();
p.setProperty("librefs", "appdev 'c:/data/tables';");
p.setProperty("username", "myUserid");
p.setProperty("password", "myPassword");
con = DriverManager.getConnection(url, p);
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * from appdev.class");
int columnCount = rs.getMetaData().getColumnCount();
out.write("<table border=1>");
out.write("<tr>");
for (int i = 1; i <= columnCount; i++) {
out.write("<th>" + rs.getMetaData().getColumnName(i) + "</th>");
}
out.write("</tr>");
while (rs.next()) {
out.write("<tr>");
for (int i = 1; i <= columnCount; i++) {
out.write("<td>" + rs.getString(i) + "</td>");
}
out.write("</tr>");
}
}catch( Exception e ){
e.printStackTrace();
}
finally{
if( null != stmt ){
stmt.close();
}
if( null != con ){
con.close();
}
}
%>
|
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This sample demonstrates how to use the SAS Integration Technologies MVADriver class to connect to a SAS Workspace Server.
Date Modified: | 2008-09-16 14:40:19 |
Date Created: | 2006-04-06 13:19:51 |
Operating System and Release Information
SAS System | SAS AppDev Studio | Microsoft® Windows® for x64 | 3.2 | | 9.1 TS1M3 SP4 | |
Microsoft Windows 2000 Advanced Server | 3.2 | | 9.1 TS1M3 SP4 | |
Microsoft Windows 2000 Datacenter Server | 3.2 | | 9.1 TS1M3 SP4 | |
Microsoft Windows 2000 Server | 3.2 | | 9.1 TS1M3 SP4 | |
Microsoft Windows 2000 Professional | 3.2 | | 9.1 TS1M3 SP4 | |
Microsoft Windows NT Workstation | 3.2 | | 9.1 TS1M3 SP4 | |
Microsoft Windows Server 2003 Datacenter Edition | 3.2 | | 9.1 TS1M3 SP4 | |
Microsoft Windows Server 2003 Enterprise Edition | 3.2 | | 9.1 TS1M3 SP4 | |
Microsoft Windows Server 2003 Standard Edition | 3.2 | | 9.1 TS1M3 SP4 | |
Microsoft Windows XP Professional | 3.2 | | 9.1 TS1M3 SP4 | |
Windows Vista | 3.2 | | 9.1 TS1M3 SP4 | |
SAS System | SAS Integration Technologies | z/OS | | | 9.1 TS1M3 SP4 | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | | | 9.1 TS1M3 SP4 | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | | | 9.1 TS1M3 SP4 | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | | | 9.1 TS1M3 SP4 | |
Microsoft Windows XP 64-bit Edition | | | 9.1 TS1M3 SP4 | |
Microsoft® Windows® for x64 | | | 9.1 TS1M3 SP4 | |
Microsoft Windows 2000 Advanced Server | | | 9.1 TS1M3 SP4 | |
Microsoft Windows 2000 Datacenter Server | | | 9.1 TS1M3 SP4 | |
Microsoft Windows 2000 Server | | | 9.1 TS1M3 SP4 | |
Microsoft Windows 2000 Professional | | | 9.1 TS1M3 SP4 | |
Microsoft Windows NT Workstation | | | 9.1 TS1M3 SP4 | |
Microsoft Windows Server 2003 Datacenter Edition | | | 9.1 TS1M3 SP4 | |
Microsoft Windows Server 2003 Enterprise Edition | | | 9.1 TS1M3 SP4 | |
Microsoft Windows Server 2003 Standard Edition | | | 9.1 TS1M3 SP4 | |
Microsoft Windows XP Professional | | | 9.1 TS1M3 SP4 | |
Windows Vista | | | 9.1 TS1M3 SP4 | |
64-bit Enabled AIX | | | 9.1 TS1M3 SP4 | |
64-bit Enabled HP-UX | | | 9.1 TS1M3 SP4 | |
64-bit Enabled Solaris | | | 9.1 TS1M3 SP4 | |
HP-UX IPF | | | 9.1 TS1M3 SP4 | |
Linux | | | 9.1 TS1M3 SP4 | |
Linux on Itanium | | | 9.1 TS1M3 SP4 | |
OpenVMS Alpha | | | 9.1 TS1M3 SP4 | |
Tru64 UNIX | | | 9.1 TS1M3 SP4 | |