Fork me on GitHub

n. Slang a rough lawless young Kuali developer.
[perhaps variant of Houlihan, Irish surname]
kualiganism n

Blog of an rSmart Java Developer. Full of code examples, solutions, best practices, et al.

Friday, April 23, 2010

Turning on Oracle Driver Tracing

You are probably asking right about now, "Why would I do this if I have p6spy?" Well, here are my reasons.
  • P6Spy is a proxy on the driver. It watches SQL that goes in and prints it.
  • OJDBC in debug mode prints what goes in (not just SQL).
  • OJDBC in debug mode reports what comes out (including exceptions!)
Basically, if there's an exception or any kind of warning handled by the driver, you would find out about it. This is useful for too many reasons to count. Further, it doesn't just spit out the SQL you send it. It spits out any requests to recover connections or API level communication happening in the backend. Really, anything over Net8 happens will get reported. That's huge if you're working with Oracle.

Without further ado, here it is. Pass the following in when starting your JVM.

-Doracle.jdbc.Trace=true -Djava.util.logging.config.file=<location of your java logging configuration file>

Note: You must use the ojbdcX_g.jar.
Oracle optimizes its driver library for each JVM. ojdbc14.jar is optimized for jdk 1.4. ojdbc5.jar is optimized for java 5. ojdbc6.jar is optimized for java 6. _g is appended for the debugging enabled jar. For example, ojdbc14_g.jar is the jdk1.4 jar with debugging enabled.

ojdbc debug mode uses java.util.logging framework to define its logging. You simply configure it. Here is what our config looks like:


We use a java.util.logging.FileHandler, but you can use the ConsoleHandler which is useful for development; however, this merges all your logs to file which may not always be ideal

That's it. If you're working with tomcat, just set this in your CATALINA_OPTS environment variable. You can also set this in your Eclipse JRE settings for your Kuali project. If you're using eclipse, you may want to look at the Eclipse Log Viewer plugin which will allow you to follow external logs from within eclipse.

1 comment:

  1. If you're coming from a syndicated URL post you may also want to see