I am working on a SQL Logger for my web application. I want to be able to Log the SQL query that is fired by user-interaction with the GUI. I\'m working in a Spring environm
i use jdbcdslog-exp for cases like this.
add jdbcdslog-1.0.6.2.jar to classpath.
add categories to log4j configuration (set INFO for ResultSetLogger too if you want - beware of OutOfMemory)
<category name="org.jdbcdslog.StatementLogger">
<priority value="INFO"/>
</category>
<category name="org.jdbcdslog.ResultSetLogger">
<priority value="FATAL"/>
</category>
if you need to switch statement logging by runtime you can start your log4j with
PropertyConfigurator.configureAndWatch("log4j.xml", 60000);
change your jdbc connection parameters (here example for hsql in jboss)
from
<connection-url>jdbc:hsqldb:hsql://localhost:1801</connection-url>
<driver-class>org.hsqldb.jdbcDriver</driver-class>
to
<connection-url>jdbc:jdbcdslog:hsqldb:hsql://localhost:1801;targetDriver=org.hsqldb.jdbcDriver</connection-url>
<driver-class>org.jdbcdslog.DriverLoggingProxy</driver-class>