Techniques for testing a Java routine
You can test your Java routines as stand-alone programs, use IBM Db2 for z/OS Developer Extension, 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 Db2 Developer Extension (stored procedures only)
Db2 Developer Extension is an extension for Microsoft Visual Studio Code that provides language support for Db2 for z/OS SQL. It provides a graphical user interface for debugging Java stored procedures. For information on using Db2 Developer Extension to debug Java stored procedures, see Debugging external Java and SQLJ stored procedures.
- Customize and run the DSNTIJRT program to define stored procedures that provide server support for Db2 Developer Extension.
DSNTIJSD is in the prefix.SDSNSAMP data set. The job prolog contains customization instructions.
- Define the stored procedure that you intend to test with the ALLOW DEBUG MODE option in the CREATE PROCEDURE or ALTER PROCEDURE statement.
- 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.
. - Grant the DEBUGSESSION privilege to the user who runs the debug client.
- 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.