ASA Programming Guide
JDBC Programming
Establishing JDBC connections
Connecting from a JDBC client application using jConnect
The external connection example is a Java command-line application.
The application requires several libraries, which are imported in the first lines of JDBCExamples.java:
The java.sql package contains the Sun Microsystems JDBC classes, which are required for all JDBC applications. You'll find it in the classes.zip file in your Java subdirectory.
Imported from com.sybase.jdbc2.jdbc, the Sybase jConnect JDBC driver is required for all applications that connect using jConnect.
The application uses a property list. The java.util.Properties class is required to handle property lists. You'll find it in the classes.zip file in your Java subdirectory.
The asademo package contains classes used in some samples. You'll find it in the Samples\ASA\Java\asademo.jar file.
Each Java application requires a class with a method named main, which is the method invoked when the program starts. In this simple example, JDBCExamples.main is the only public method in the application.
The JDBCExamples.main method carries out the following tasks:
Processes the command-line argument, using the machine name if supplied. By default, the machine name is localhost, which is appropriate for the personal database server.
Calls the ASAConnect method to establish a connection.
Executes several methods that scroll data to your command-line.
The JDBCExamples.ASAConnect method carries out the following tasks:
Connects to the default running database using Sybase jConnect.
Class.forName loads jConnect. Using the newInstance method, it works around issues in some browsers.
The StringBuffer statements build up a connection string from the literal strings and the supplied machine name provided on the command-line.
DriverManager.getConnection establishes a connection using the connection string.
Returns control to the calling method.