Deploying Java routine class files to database servers

Java™ routine implementations must be deployed to the database server file system so that they can be located, loaded, and run upon routine invocation.

One or more Java routine implementations can be included in an individual Java class file. Java class files that contain Java routine implementations can be collected together into JAR files. The Java class files that you use to implement a routine must reside in a JAR file that is installed in the target database.

Prerequisites:
  • Identify the database server to which you want to deploy the routine class.
  • On UNIX and Linux® operating systems, identify the user ID of the database instance owner. If this is not known, see your database administrator.
  • Determine if the location where you deploy the routine class is accessible on all of the hosts in the db2nodes.cfg file. Consider packaging your routine class files into a JAR file and installing the JAR on the database server with the SQLJ.INSTALL_JAR procedure.
To deploy individual Java routine class files:
  • Copy the Java routine class into the database function directory.

    On UNIX and Linux operating systems, the function directory is defined as: install_path/function where install_path is the database manager installation path. For example, $HOME/sqllib/function, where $HOME is the home directory of the instance owner.

    On Windows operating systems, the function directory is defined as: instance_profile_path\function where the instance_profile_path is the path, which was specified in the db2icrt (create instance) command. You can find the instance profile path name by issuing the db2set command as follows:
    db2set DB2INSTPROF
    For example, C:\Documents and Settings\All Users\Application Data\IBM\DB2\db2copy1\function

    If you declare a class to be part of a Java package, create subdirectories in the function directory that correspond to the fully qualified class names and place the related class files in the corresponding subdirectory. For example, if you create a class called ibm.tests.test1 for a Linux operating system, store the corresponding Java bytecode file (named test1.class) in $HOME/sqllib/function/ibm/tests, where $HOME is the home directory of the instance owner.

To deploy JAR files that contain Java routine class files:

Once the Java routine class files is deployed and the CREATE statement has been executed to define the routine in the database, you can invoke the routine.

Deploying Java routine class files to database servers with dependent classes

When the Java routine class files have dependencies on classes that are not part of the standard Java or database classes, repeat the steps that are identified in the previous section for each dependent class.

Alternatively, the database can be configured to search the directories in the CLASSPATH environment variable in order to detect dependant classes. On Windows operating systems, the database manager searches the specified directories in the CLASSPATH system environment variable. On UNIX and Linux operating systems, the database manager searches the instance owner's CLASSPATH environment variable if the text " CLASSPATH " is specified as part of the DB2ENVLIST environment variable. It is strongly recommended that dependant classes be installed rather than relying on the CLASSPATH environment variable.