INSTALL JAVA statement

Use this statement to make Java classes available for use within a database.

Syntax
INSTALL JAVA
[ NEW | UPDATE ]
[ JAR jar-name ]
FROM { FILE filename | expression }
Parameters
  • NEW and UPDATE keyword clauses   If you specify an install mode of NEW, the referenced Java classes must 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 is used.

    If you specify UPDATE, the referenced Java classes may include replacements for Java classes that are already installed in the given database.

    If install-mode is omitted, the default is NEW.

  • JAR clause   If this is specified, then the filename must designate a jar file. JAR files typically have extensions of .jar or .zip.

    Installed jar and zip files can be compressed or uncompressed.

    If the JAR option is specified, 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 jars installed in a database with the JAR option are called the retained jars of the database.

    The jar-name is a character string value, of up to 255 bytes long. The jar-name is used to identify the retained jar in subsequent INSTALL JAVA, UPDATE, and REMOVE JAVA statements.

  • FROM FILE clause   Specifies the location of the Java class(es) to be installed.

    The formats supported for filename 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 filename must identify either a class file, or a jar file.

  • FROM clause   Expressions must evaluate to a binary type whose value contains a valid class file or jar file.

Remarks

The class definition for each class is loaded by each connection's VM 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 has an install-mode of NEW or UPDATE. Because the VM is restarted, any values stored in Java static variables are lost, and any SQL variables with Java class types are dropped.

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.

Permissions

DBA permissions are required to execute the INSTALL JAVA statement.

All installed classes can be referenced in any way by any user.

Not supported on Windows Mobile.

See also
Standards and compatibility
  • SQL/2003   Vendor extension.

Example

The following statement installs 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';

The following statement installs all the classes contained in a zip file, and associates them within the database with a JAR file name.

INSTALL JAVA
JAR 'Widgets'
FROM FILE 'C:\Jars\Widget.zip';

Again, 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).