JBoss show JDBC Queries

Sometimes it is necessary to see which queries are executed and what the parameters of these queries have been. To get this data from a JBoss 7+ you have to follow these steps:

Enable JDBC-Spy on Datasource:

/subsystem=datasources/data-source=ExampleDS/:write-attribute(name=spy,value=true)

Or just add spy=”true” as attribute in standalone.xml.

Then you have to enable the spy by adding a loglevel:

/subsystem=logging/logger=jboss.jdbc.spy/:add(level=TRACE)

If this doesn’t output anything your loglevel is above trace. Default is INFO. So nothing is displayed.

Add the following part to your logging configuration to enable TRACE-logging for a single package:

<subsystem xmlns="urn:jboss:domain:logging:2.0">
...
<console-handler name="TRACER">
  <level name="TRACE"/>
  <formatter>
    <named-formatter name="COLOR-PATTERN"/>
  </formatter>
</console-handler>
...
<logger category="jboss.jdbc.spy" use-parent-handlers="false">
  <level name="TRACE"/>
  <handlers>
    <handler name="TRACER"/>
  </handlers>
</logger>
...
</subsystem>

I didn’t use command line for this but of course it would be possible to do so.

Leave a Comment