Home > Articles > Data

Like this article? We recommend

Connecting to ASA

Connections to ASA databases are made via the supplied jConnect JDBC Driver, which is contained in the jconn2.jar file stored in the Sybase\Shared\jConnect-5_5 directory after installation. To access this JAR file from your application, simply include jconn2.jar in your classpath, as you would any other Java archive. This archive includes Sybase's 100% pure JDBC driver. A separate driver is included for applications that want to connect to an RDBMS using a JDBC-ODBC bridge. As with any JDBC application, the first step is to obtain a java.sql.Connection object that can be used to query the database. The following code snippet illustrates how this would be done:

Properties props = new Properties();
props.put( "user", "admin" );
props.put( "password", "123456" );
Class.forName( "com.sybase.jdbc.SybDriver" ).newInstance();
String URL = "jdbc:sybase:Tds:localhost";
Connection conn = DriverManager.getConnection( URL , props );

The connection above was obtained using a "ServiceName" parameter, which must be of the following syntax:

jdbc:sybase:Tds:machine-name:port-number?ServiceName=DBN

Typecasting the com.sybase.jdbc.SybDriver class allows us to also use the SybDriver class' setRemotePassword() method to pass additional parameters.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.