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

SQL Anywhere 12.0.0 » SQL Anywhere Server - Programming » JDBC support » Connecting from a JDBC client application » Establishing a connection from a server-side JDBC class

 

Running the server-side connection example

 To create and execute the internal connection example application
  1. At a command prompt, change to the samples-dir\SQLAnywhere\JDBC directory.

  2. Start a database server with the sample database on your local computer using the following command:

    dbeng12 samples-dir\demo.db
  3. For server-side JDBC, it is not necessary to set the CLASSPATH environment variable.

  4. Enter the following command to compile the example:

    javac JDBCConnect2.java
  5. Install the class into the sample database using Interactive SQL. Run the following statement:

    INSTALL JAVA NEW
    FROM FILE 'samples-dir\SQLAnywhere\JDBC\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 choose 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:

    CREATE PROCEDURE JDBCConnect()
      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.