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.
- Identify the database server to which you want to deploy the routine class.
- 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.
- Copy the Java routine class
into the database function directory.
The database 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.
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, 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.
- If the location where you deployed the routine class is not accessible on all of the hosts in the db2nodes.cfg file, copy the routine class to the same location on each host.
- You must install the JAR file that contains Java routine class files to the database server file system. Refer to JAR file administration on the database server.
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. The database manager searches the instance owner's CLASSPATH environment variable. It is strongly recommended that dependant classes be installed rather than relying on the CLASSPATH environment variable.