Running the Server-Side Connection Example

The steps involved in creating and executing a JDBC server-side 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 server-side connection.

  1. At a command prompt, change to the %ALLUSERSPROFILE%\SybaseIQ\samples\SQLAnywhere\JDBC directory.
    cd %ALLUSERSPROFILE%\SybaseIQ\samples\SQLAnywhere\JDBC
  2. For server-side JDBC, it is not necessary to set the CLASSPATH environment variable unless the server will be started from a different current working directory.
    set classpath=.;%ALLUSERSPROFILE%\SybaseIQ\samples\SQLAnywhere\JDBC
  3. Start a database server with the iqdemo database on your local computer.
  4. Enter the following command to compile the example:
    javac JDBCConnect2.java
  5. Install the class into the sample database using Interactive SQL. Execute the following statement (a path to the class file may be required):
    INSTALL JAVA NEW
    FROM FILE 'JDBCConnect2.class';
  6. Define a stored procedure named JDBCConnect that acts as a wrapper for the JDBCConnect2.main method in the class:
    CREATE PROCEDURE JDBCConnect(OUT args LONG VARCHAR)
      EXTERNAL NAME 'JDBCConnect2.main([Ljava/lang/String;)V'
      LANGUAGE JAVA;
  7. Call the JDBCConnect2.main method as follows:
    CALL JDBCConnect();

    The first time a Java class is called in a session, the Java VM must be loaded. This might take a few seconds.

  8. Confirm that a list of identification numbers with customers' names appears in the database server messages window.

    If the attempt to connect fails, an error message appears instead. Confirm that you have executed all the steps as required.

A list of identification numbers with customer's names is displayed in the database server messages window.