DB2 10.5 for Linux, UNIX, and Windows

Examples of using configuration properties to start a JDBC trace

You can control tracing of JDBC applications without modifying those applications.

Example of writing trace data to one trace file for each connection

Suppose that you want to collect trace data for a program named Test.java, which uses IBM® Data Server Driver for JDBC and SQLJ type 4 connectivity. Test.java does no tracing, and you do not want to modify the program, so you enable tracing using configuration properties. You want your trace output to have the following characteristics:
  • Trace information for each connection on the same DataSource is written to a separate trace file. Output goes into a directory named /Trace.
  • Each trace file name begins with jccTrace1.
  • If trace files with the same names already exist, the trace data is appended to them.

Although Test.java does not contain any code to do tracing, you want to set the configuration properties so that if the application is modified in the future to do tracing, the settings within the program will take precedence over the settings in the configuration properties. To do that, use the set of configuration properties that begin with db2.jcc, not db2.jcc.override.

The configuration property settings look like this:
  • db2.jcc.traceDirectory=/Trace
  • db2.jcc.traceFile=jccTrace1
  • db2.jcc.traceFileAppend=true
You want the trace settings to apply only to your stand-alone program Test.java, so you create a file with these settings, and then refer to the file when you invoke the Java™ program by specifying the -Ddb2.jcc.propertiesFile option. Suppose that the file that contains the settings is /Test/jcc.properties. To enable tracing when you run Test.java, you issue a command like this:
java -Ddb2.jcc.propertiesFile=/Test/jcc.properties Test
Suppose that Test.java creates two connections for one DataSource. The program does not define a logWriter object, so the driver creates a global logWriter object for the trace output. When the program completes, the following files contain the trace data:
  • /Trace/jccTrace1_global_0
  • /Trace/jccTrace1_global_1

Example of doing a circular trace with a fixed number of files and fixed file size

Suppose that you want to collect trace data for a program named Test.java, which uses IBM Data Server Driver for JDBC and SQLJ type 4 connectivity. Test.java does no tracing, and you do not want to modify the program, so you enable tracing using configuration properties. You want your trace output to have the following characteristics:
  • Trace information for each connection on the same DataSource is written to a separate set of trace files.
  • The maximum number of trace files that are written for each connection is 4.
  • When all trace files are full, the trace overwrites existing trace data, beginning with the first trace file that was written.
  • The maximum size of each trace file is 4 MB.
  • Each trace file name begins with jcc.log, and is written into a directory named /Trace.
  • If trace files with the same names already exist, the trace data is overwritten.

Although Test.java does not contain any code to do tracing, you want to set the configuration properties so that if the application is modified in the future to do tracing, the settings within the program will take precedence over the settings in the configuration properties. To do that, use the set of configuration properties that begin with db2.jcc.

The configuration property settings look like this:
  • db2.jcc.traceFile=jcc.log
  • db2.jcc.traceOption=1
  • db2.jcc.traceFileSize=4194304
  • db2.jcc.traceFileCount=4
  • db2.jcc.traceFileAppend=false
You want the trace settings to apply only to your stand-alone program Test.java, so you create a file with these settings, and then refer to the file when you invoke the Java program by specifying the -Ddb2.jcc.propertiesFile option. Suppose that the file that contains the settings is /Test/jcc.properties. To enable tracing when you run Test.java, you issue a command like this:
java -Ddb2.jcc.propertiesFile=/Test/jcc.properties Test

Suppose that Test.java creates two connections for one DataSource. The program does not define a logWriter object, so the driver creates a global logWriter object for the trace output. During execution of the program, the IBM Data Server Driver for JDBC and SQLJ writes 17 MB of data for the first connection, and 10 MB of data for the second connection.

When the program completes, the following files contain the trace data:

/Trace/jcc.log_global_0.1 contains the last 1 MB of trace data that is written for the first connection, which overwrites the first 1 MB of trace data that was written for that connection.