Saturday, April 29, 2006

Java Cover Story — Debugging JDBC with a Logging Driver @ JAVA DEVELOPER'S JOURNAL

Java Cover Story — Debugging JDBC with a Logging Driver @ JAVA DEVELOPER'S JOURNAL: "Java Cover Story — Debugging JDBC with a Logging Driver
A new way to debug and solve DB problems

By: Ryan Bloom
Apr. 28, 2006 12:30 PM

A couple of years ago I began developing in Java, and my first Java project required that I also learn SQL. Our project team was using mostly EJBs for database access, although for some performance-critical sections of the application we wrote the JDBC logic directly. A problem that we faced regularly was tracking the bind parameters to our PreparedStatements. Over the course of the project, all of the team members tried different techniques to determine what our JDBC statements were actually doing."

Includes logging of Hibernate HQL, via logging in the JDBC driver. I do not necessarily agree with this approach as the author points out - this is an aspect that cuts across the system so I'd prefer a solution using AOP to log the statements.

In fact the more I think about it the more I like AOP used for logging. Although log4j is very efficient, and adding if(debug) conditionals can improve the performance further - it seems to me that either including or not inclduing an aspect to log would be the preferred approach as it does not pollute the code and can be switched on and off - when off there is absolutely no impact on performance. It is a clean and elegent approach.

Read the comments in this article and you will see it has been debunked, and there are existing resources out there that do the same thing already - see Tuning JDBC: Measuring JDBC performance by Jack Shirazi, author of Java Performance Tuning
and this tool

No comments: