Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SAP Sybase SQL Anywhere 16.0 » SQL Anywhere Server - Programming » JDBC support » How to establish a connection from a server-side JDBC class


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.


A Java Development Kit (JDK) must be installed.

You must have the following system privileges.

  • MANAGE ANY EXTERNAL OBJECT to install Java classes

  • CREATE PROCEDURE and CREATE EXTERNAL REFERENCE to create external procedures

Contexte et remarques

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 %SQLANYSAMP16%\SQLAnywhere\JDBC directory.

    cd %SQLANYSAMP16%\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=.;%SQLANYSAMP16%\SQLAnywhere\JDBC
  3. Start a database server with the sample database on your local computer using the following command:

    dbsrv16 "%SQLANYSAMP16%\demo.db"
  4. Enter the following command to compile the example:

  5. Install the class into the sample database using Interactive SQL. Execute the following statement (a path to the class file may be required):

    FROM FILE 'JDBCConnect2.class';

    You can also install the class using Sybase Central. While connected to the sample database, open the Java subfolder under External Environments and click File » New » Java Class. Then follow the instructions in the wizard.

  6. Define a stored procedure named JDBCConnect that acts as a wrapper for the JDBCConnect2.main method in the class:

      EXTERNAL NAME 'JDBCConnect2.main([Ljava/lang/String;)V'
  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 customer 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 names is displayed in the database server messages window.