Techniques for testing a Java routine

You can test your Java routines as stand-alone programs, use the IBM® Data Studio routine debugger, or write your own debug information from the routines.

Test your routine as a stand-alone program

Before you invoke your Java routines from SQL applications, it is a good idea to run the routines as stand-alone programs, which are easier to debug. A Java program that runs as a routine requires only a DB2® package. However, before you can run the program as a stand-alone program, you need to bind a DB2 plan for it.

Use the IBM Data Studio routine debugger (stored procedures only)

The IBM Data Studio routine debugger is available with DB2 Database for Linux, UNIX, and Windows. The IBM Data Studio routine debugger provides a GUI interface for debugging Java stored procedures. For information on the IBM Data Studio routine debugger, see Routine debugger (IBM Data Studio).

To set up a DB2 for z/OS® subsystem to work with the IBM Data Studio routine debugger, when you set up your stored procedure environment, follow these additional steps:
  1. Start of changeCustomize and run the DSNTIJRT program to define stored procedures that provide server support for the IBM Data Studio routine debugger.End of change

    DSNTIJSD is in the prefix.SDSNSAMP data set. The job prolog contains customization instructions.

  2. Define the stored procedure that you intend to test with the ALLOW DEBUG MODE option in the CREATE PROCEDURE or ALTER PROCEDURE statement.
  3. When you prepare the stored procedure for execution, specify the -g option in the javac command

    -g causes the compiler to generate all debugging information for the program.

    .
  4. Grant the DEBUGSESSION privilege to the user who runs the debug client.
  5. Make the following modifications to the WLM environment for the stored procedure:
    • In the WLM environment startup procedure, set NUMTCB=1
    • In the WLM environment startup procedure, include a PSMDEBUG DD statement to direct the debug diagnostic log to a data set. You can allocate to a SYSOUT data set or to a preallocated data set. The data set needs to be created with the RECFM=VBA and LRECL=4096 characteristics.
    • In the ENVAR settings in the JAVAENV data set, set USE_LIBJVM_G=YES.
    • If the debug port range of 8000::8050 is not acceptable, in the ENVAR settings in the JAVAENV data set, set JVM_DEBUG_PORTRANGE to the range of ports that the JVM listens on for debug connections.

Enable collection of DB2 debug information

Include a JSPDEBUG DD statement in your startup procedure for the stored procedure address space. This DD statement specifies a data set to which DB2 writes debug information for use by IBM Software Support.

Write your own debug information from your routine

A useful technique for debugging is to include System.out.println and System.err.println calls in your program to write messages to the STDERR and STDOUT files.

STDERR and STDOUT output is written to the directory that is specified by the WORK_DIR parameter in the JAVAENV data set, if that directory exists. If no WORK_DIR parameter is specified, output goes to the default directory, /tmp/java, if that directory exists.