Differences between Java routines and other routines

Java routines differ in a few basic ways from routines that are written in other programming languages.

A Java routine differs from stored procedures that are written in other languages in the following ways:
  • A Java routine must be defined with PARAMETER STYLE JAVA. PARAMETER STYLE JAVA specifies that the routine uses a parameter-passing convention that conforms to the Java language and SQLJ specifications. Db2 passes INOUT and OUT parameters as single-entry arrays. This means that in your Java routine, you must declare OUT or INOUT parameters as arrays. For example, suppose that stored procedure sp_one_out has one output parameter of type int. You declare the parameter like this:
    public static void routine_one_out (int[] out_parm)
  • Java routines that are Java main methods have these restrictions:
    • The method must have a signature of String[]. It must be possible to map all the parameters to Java variables of type java.lang.String.
    • The routine can have only IN parameters.
  • You cannot make instrumentation facility interface (IFI) calls in Java routines.
  • You cannot specify an SQL access level of NO SQL for Java routines.
  • As in other Java programs, you cannot include the following statements in a Java routine:
    • CONNECT
    • RELEASE
    • SET CONNECTION
  • Routine parameters have different mappings to host language data types than the mappings of routine parameters to host language parameters for other languages.
  • The technique for returning result sets from Java stored procedures is different from the technique for returning result sets in other stored procedures.
  • When a Java routine executes, Java dynamically loads classes when new class references occur in the class that is being executed. During the class loading process, a java.lang.ClassNotFoundException or java.lang.NoClassDefFoundError can be thrown. These failures can occur whether Java looks for the class in an installed JAR or in the CLASSPATH. If the Java routine does not catch these errors and exceptions, the routine terminates and an SQL error condition is reported.