Running the Connection Example

The steps involved in creating and executing a JDBC application are shown through the use of an example.

Prerequisites

A Java Development Kit (JDK) must be installed.

Task

Two different types of connections using JDBC can be made. One is the client-side connection and the other is the server-side connection. The following example uses a client-side connection.

  1. At a command prompt, change to the %ALLUSERSPROFILE%\SybaseIQ\samples\SQLAnywhere\JDBC directory.
  2. Start a database server with the iqdemo.db database on your local computer.
  3. Set the CLASSPATH environment variable. The SQL Anywhere JDBC 4.0 driver contained in sajdbc4.jar is used in this example.
    set classpath=.;%IQDIR%\java\sajdbc4.jar

    If you are using the jConnect driver instead, then use the following (where path is your jConnect installation directory):

    set classpath=.;jconnect-path\classes\jconn4.jar
  4. Run the following command to compile the example:
    javac JDBCConnect.java
  5. Run the following command to execute the example:
    java JDBCConnect

    Add a command line argument such as jconnect to load a different JDBC driver.

    java JDBCConnect jconnect
  6. Confirm that a list of identification numbers with customer's names appears at the command prompt.

    If the attempt to connect fails, an error message appears instead. Confirm that you have executed all the steps as required. Check that your class file path is correct. An incorrect setting may result in a failure to locate a class.

A list of identification numbers with customer's names is displayed.