Preparing Java routines with no SQLJ clauses to run from a JAR file

The recommended method of running Java routines is to run them from a JAR file.

About this task

The steps in this task prepare a JDBC routine for execution, create a JAR file for the routine, define the JAR file and routine to Db2, and grant access on the routine to users.

Procedure

  1. Run the javac command to compile the Java program to produce Java bytecodes.
  2. Run the jar command to collect the class files that contain the methods for your routine into a JAR file. See 'Creating JAR files for Java routines" for information on creating the JAR file.
  3. Call the INSTALL_JAR stored procedure to define the JAR file to Db2.
  4. If the installed JAR references classes in other installed JARs, call the SQLJ.ALTER_JAVA_PATH stored procedure to specify the class resolution path that the JVM searches to resolve those class references.
  5. If another user defines the routine to Db2, execute the SQL GRANT USAGE ON JAR statement to grant the privilege to use the JAR file to that user.
  6. Execute the SQL CREATE PROCEDURE or CREATE FUNCTION statement to define the routine to Db2. Specify the EXTERNAL NAME parameter with the name of the JAR that you defined to Db2 in step 3.
  7. Execute the SQL GRANT statement to grant the EXECUTE privilege on the routine to the appropriate users.