I'm working on an application that uses a cached ConnectionPool based on the latest Oracle JDBC driver on the WebLogic application server (version 10.3). Since the pool is not controlled by WebLogic, it is very difficult to use P6Spy or other tools to see what SQL the application is generating (I've not been able to find any way to use SQL inspection tools with the current connection configuration). SQLTrace will give statement information (including performance numbers), but will not give visibility to bind variables. Finally, if there are issues with JDBC objects on the Java side, SQLTrace is of little help.
This page offers configurable logging around JDBC operations, including bind variable visibility and column-level return value visibility. Sadly, you have to manually match up your bind variables with their respective positions in the statement, but at least bind variable values are available to you.
You'll know if you've successfully configured JDBC Diagnosability since you'll get a lot of red text appearing in the console (when using Eclipse at least) as soon as you begin to communicate with the database.
This document goes into greater detail.
Server side diagnostics
Below are the steps I took to get the debug information to print to the console. These instructions assume you are using startWebLogic.cmd to run WLS.- Locate ojdbc*_g.jar in your WLS installation. There's one for JRE 5 and one for JRE6. I found these in %WLS_HOME%\wlserver_10.3\server\ext\jdbc\oracle\11g\
- Modify startWebLogic.cmd to place the jar at the front of the classpath:
set CLASSPATH=C:\wls1032\wlserver_10.3\server\ext\jdbc\oracle\11g\ojdbc5_g.jar;%SAVE_CLASSPATH%
- Create OracleLog.properties and place it in a directory on the WLS instance. See the example at the bottom of this post. Unfortunately I've not found a good comprehensive explanation of this file, but I've thrown together something that works for console logging. Logging to a file is not working for me as of now.
- Modify WLS start script by adding -Doracle.jdbc.Trace=true and -Djava.util.logging.config.file=<OracleLog.properties>
-Doracle.jdbc.Trace=true -Djava.util.logging.config.file=C:\wls1032\wlserver_10.3\server\ext\jdbc\oracle\11g\OracleLog.properties
JUnit diagnostics
If you've got a situation that you want to debug and that you can recreate using JUnits you're in a good place. Your test will typically take less time to run than any operation via the GUI and you don't need to undeploy, shut down, restart and redeploy to a server constantly.In the Run Configurations view for your test class/method do the following:
- Add to VM arguments on the Arguments tab
-Doracle.jdbc.Trace=true -Djava.util.logging.config.file=C:/wls1032/wlserver_10.3/server/ext/jdbc/oracle/11g/OracleLog.properties
- On the Classpath tab, click Add External JARs and locate your ojdbcX_g.jar file (where X is '5' or '6' per your JDK version), then click Up to make sure this comes before any other things in the User Entries selection
- Run your test using the Run Configuration you've modified.
OracleLog.properties example
# OracleLog.properties Copyright Oracle 2007
# Controls output of java.util.logging output for Oracle JDBC drivers
# See the Javadoc for OracleLog for more information.
# The OracleLog system uses the services of
# java.util.logging.* This file is a starting
# point for controlling that output via a properties
# file. Note that there is also a programatic interface
# for java.util.logging which may be used as well. That
# would allow finer grained control and the ability to
# change the logging as the program runs.
# Copy this file to your runtime directory to use as a
# starting point. You should expect to change it to
# suit your needs.
# To enable logging controlled by this file start your
# main java class with the swtiches
# -Doracle.jdbc.Trace=true
# -Djava.util.logging.config.file=OracleLog.properties
# -Djava.util.logging.config.file=C:\wls1032\wlserver_10.3\server\ext\jdbc\oracle\11g\OracleLog.properties
# See also the file logging.properties in the jre/lib directory
# in your JDK installation and the JDK documentation.
# default file output is in user's home directory.
java.util.logging.FileHandler.pattern = C:\wls1032\wlserver_10.3\server\ext\jdbc\oracle\11g\app_jdbc.log
java.util.logging.FileHandler.limit = 500000
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
# log to the console by default
handlers = java.util.logging.ConsoleHandler
# for sqlnet tracing uncomment the lines below
# oracle.jdbc.diagnostics.DemultiplexingLogHandler.pattern= jdbc_%s.trc
# oracle.jdbc.diagnostics.DemultiplexingLogHandler.formatter = java.util.logging.SimpleFormatter
# handlers = oracle.jdbc.diagnostics.DemultiplexingLogHandler
# default is to log everything generated. control what is generated below
java.util.logging.ConsoleHandler.level = ALL
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
# JDBC uses the following Levels. Levels lower than FINE produce output that
# may not be meaningful to users. Levels lower than FINER will produce very
# large volumes of output.
#
# INTERNAL_ERROR Internal Errors
# SEVERE SQLExceptions
# WARNING SQLWarnings and other invisible problems
# INFO Public events such as connection attempts or RAC events
# CONFIG SQL statements
# FINE Public APIs
# TRACE_10 Internal events
# FINER Internal APIs
# TRACE_20 Internal debug, sqlnet tracing (oracle.net.ns.level)
# TRACE_30 High volume internal APIs
# FINEST High volume internal debug
# Uncomment and/or change the levels for more detail
oracle.jdbc.level = FINEST
oracle.jdbc.connector.level = FINEST
oracle.jdbc.driver.level = FINEST
oracle.jdbc.internal.level = FINEST
oracle.jdbc.oci.level = FINEST
oracle.jdbc.oracore.level = FINEST
oracle.jdbc.pool.level = FINEST
oracle.jdbc.rowset.level = FINEST
oracle.jdbc.util.level = FINEST
oracle.jdbc.xa.level = FINEST
oracle.jdbc.xa.client.level = FINEST
oracle.jpub.level = FINEST
oracle.net.ns.level = FINEST
oracle.sql.level = FINEST