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 » Java in the database » Tutorial: Using Java in the database

 

Lesson 3: Installing a Java class

Java classes must be installed into a database before they can be used. You can install classes from Sybase Central or Interactive SQL.

Prérequis

Complete the steps in Lesson 1 and 2 before attempting Lesson 3.

This lesson assumes that you have the roles and privileges listed in the Privileges section at the start of this tutorial: Tutorial: Using Java in the database.

Contexte et remarques

The database server uses the CLASSPATH environment variable to locate a file during the installation of classes. If the file listed in the INSTALL JAVA statement is located in a directory or ZIP file specified by the database server's CLASSPATH environmental variable, the server successfully locates the file and installs the class.

 Task
  1. Check to see if the CLASSPATH environment variable is correctly set from the first lesson. It should include the directory containing the Invoice.class file.

    CALL sa_split_list(CAST(xp_getenv('CLASSPATH') AS LONG VARCHAR), ';');
  2. Use Interactive SQL to execute a statement like the following. The path to the location of your compiled class file is not required if it can be located using the database server's CLASSPATH. The path, if specified, must be accessible to the database server.

    INSTALL JAVA NEW 
    FROM FILE 'path\\Invoice.class';

Résultat

The class is now installed into the sample database.

Subsequent changes made to the class file are not reflected automatically in the copy of the class file in the database. Whenever the class file is recompiled, use the INSTALL JAVA UPDATE statement to reload the class file into the database.

Suivant

In the next lesson, you call the methods in the Java class from SQL. Proceed to Lesson 4: Calling methods in a Java class.

 See also