Show TOC

INSTALL JAVA StatementLocate this document in the navigation structure

Makes Java classes available for use within a database.

Syntax
INSTALL JAVAinstall-mode ] [ JAR <jar-name> ] 
   FROM source

install-mode - (back to Syntax)NEW | UPDATE }

source - (back to Syntax)
   { FILE <file-name> | URL <url-value> }
Parameters

(back to top)

  • NEW (default) requires that the referenced Java classes be new classes, rather than updates of currently installed classes. An error occurs if a class with the same name exists in the database and the NEW install mode clause is used
  • UPDATE an install mode of specifies that the referenced Java classes may include replacements for Java classes already installed in the given database.
  • JAR a character string value of up to 255 bytes that is used to identify the retained JAR in subsequent INSTALL, UPDATE, and REMOVE statements. <jar-name> or text-pointer must designate a JAR file or a column containing a JAR. JAR files typically have extensions of .jar or .zip.

    Installed JAR and zip files can be compressed or uncompressed. However, JAR files produced by the Sun JDK jar utility are not supported. Files produced by other zip utilities are supported.

    If the JAR option is specified, then the JAR is retained as a JAR after the classes that it contains have been installed. That JAR is the associated JAR of each of those classes. The set of JARs installed in a database with the JAR clause are called the retained JARs of the database.

    Retained JARs are referenced in INSTALL and REMOVE statements. Retained JARs have no effect on other uses of Java-SQL classes. Retained JARs are used by the SQL system for requests by other systems for the class associated with given data. If a requested class has an associated JAR, the SQL system can supply that JAR, rather than the individual class.

  • source specifies the location of the Java classes to be installed and must identify either a class file or a JAR file.

    The formats supported for <file-name> include fully qualified file names, such as 'c:\libs\jarname.jar' and '/usr/u/libs/jarname.jar', and relative file names, which are relative to the current working directory of the database server.

    The class definition for each class is loaded by the VM of each connection the first time that class is used. When you INSTALL a class, the VM on your connection is implicitly restarted. Therefore, you have immediate access to the new class, whether the INSTALL uses an install-mode clause of NEW or UPDATE.

    For other connections, the new class is loaded the next time a VM accesses the class for the first time. If the class is already loaded by a VM, that connection does not see the new class until the VM is restarted for that connection (for example, with a STOP JAVA and START JAVA).

Examples

(back to top)

  • Example 1 install the user-created Java class named “Demo” by providing the file name and location of the class:
    INSTALL JAVA NEW 
    FROM FILE 'D:\JavaClass\Demo.class'

    After installation, the class is referenced using its name. Its original file path location is no longer used. For example, this statement uses the class installed in the previous statement:

    CREATE VARIABLE d Demo

    If the Demo class was a member of the package sybase.work, the fully qualified name of the class must be used:

    CREATE VARIABLE d sybase.work.Demo
  • Example 2 install all the classes contained in a zip file and associate them within the database with a JAR file name:
    INSTALL JAVA 
    JAR 'Widgets' 
    FROM FILE 'C:\Jars\Widget.zip'

    The location of the zip file is not retained and classes must be referenced using the fully qualified class name (package name and class name).

Usage

(back to top)

Only new connections established after installing the class, or that use the class for the first time after installing the class, use the new definition. Once the Java VM loads a class definition, it stays in memory until the connection closes.

If you have been using a Java class or objects based on a class in the current connection, you need to disconnect and reconnect to use the new class definition.

Standards

(back to top)

  • SQL—Vendor extension to ISO/ANSI SQL grammar.
  • SAP Database products—Not supported by SAP ASE.
Permissions

(back to top)

  • Requires the MANAGE ANY EXTERNAL OBJECT system privilege and a newer version of the compiled class file or JAR file available in a file on disk.
  • All installed classes can be referenced in any way by any user.