You can access Java™ programs from SQL statements and programs. This can be done using Java stored procedures and Java user-defined functions (UDFs).
To use Java SQL routines, complete the following tasks:
Because any Java SQL routine may use SQLJ, make SQLJ runtime support always available when running Java 2 Software Development Kit (J2SDK). To enable runtime support for SQLJ in J2SDK, add a link to the SQLJ runtime.zip file from your extensions directory. For more information, see Setting up your server to use SQLJ.
A Java SQL routine processes a Java method from SQL. This method must be written using either the DB2® or SQLJ parameter passing conventions. See Java stored procedures, Java user-defined functions, and Java user-defined table functions for more information about coding a method used by a Java SQL routine.
Java SQL routines written using the Java parameter style may be compiled without any addition setup. However, Java SQL routines using the DB2GENERAL parameter style must extend either the com.ibm.db2.app.UDF class or com.ibm.db2.app.StoredProc class. These classes are contained in the JAR file, /QIBM/ProdData/Java400/ext/db2routines_classes.jar. When using javac to compile these routines, this JAR file must exist in the CLASSPATH. For example, the following command compiles a Java source file containing a routine which uses the DB2GENERAL parameter style:
javac -DCLASSPATH=/QIBM/ProdData/Java400/ext/db2routines_classes.jar source.java
The user-defined classes used by the database JVM can either reside in the /QIBM/UserData/OS400/SQLLib/Function directory or in a JAR file registered to the database.
The /QIBM/UserData/OS400/SQLLib/Function is the iSeries™ equivalent of /sqllib/function, the directory where DB2 UDB stores Java stored procedures and Java UDFs on other platforms. If the class is part of a Java package, it must reside in the appropriate subdirectory. For example, if the runit class is created as part of the foo.bar package, the file runnit.class should be in the integrated file system directory, /QIBM/ProdData/OS400/SQLLib/Function/foo/bar.
The class file may also be placed in a JAR file that is registered to the database. The JAR file is registered using the SQLJ.INSTALL_JAR stored procedure. This stored procedure is used to assign a JAR ID to a JAR file. This JAR ID is used to identify the JAR file in which the class file resides. See SQLJ procedures that manipulate JAR files for more information on SQLJ.INSTALL_JAR as well as other stored procedures to manipulate JAR files.
The iSeries Navigator may be used to create a stored procedure or user-defined function that uses the Java parameter style.
A Java stored procedure is called using the SQL CALL statement. A Java UDF is a function that is called as part of another SQL statement.