Differences Between Java Routines And Stand-Alone Java Programs; Differences Between Java Routines And Other Routines - IBM DB2 Manual

Table of Contents

Advertisement

Differences between Java routines and stand-alone Java
programs

Differences between Java routines and other routines

|
176
Application Programming Guide and Reference for Java
There are a few basic difference between Java routines and stand-alone Java
programs.
Those differences are:
v In a Java routine, a JDBC connection or an SQLJ connection context can use the
connection to the data source that processes the CALL statement or the
user-defined function invocation. The URL that identifies this default connection
is jdbc:default:connection.
v The top-level method for a Java routine must be declared as static and public.
Although you can use static and final variables in a Java routine without
problems, you might encounter problems when you use static and non-final
variables. You cannot guarantee that a static and non-final variable retains its
value in the following circumstances:
– Across multiple invocations of the same routine
– Across invocations of different routines that reference that variable
v As in routines in other languages, the SQL statements that you can execute in
the routine depend on whether you specify an SQL access level of CONTAINS
SQL, READS SQL DATA, or MODIFIES SQL DATA.
Related concepts
"Differences between Java routines and other routines"
Related reference
"SQL statements allowed in external functions and stored procedures" (DB2
SQL Reference)
There are a few basic difference between Java routines and routines in other
programming languages.
A Java routine differs from stored procedures that are written in other languages in
the following ways:
v 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)
v 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.
v You cannot make instrumentation facility interface (IFI) calls in Java routines.
v You cannot specify an SQL access level of NO SQL for Java routines.
v As in other Java programs, you cannot include the following statements in a
Java routine:
– CONNECT
– RELEASE

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents