Use logback to log spring JdbcTemplate SQL parameters

I am using Logback with Spring JdbcTemplate to log my SQL queries. My configurations contain the following line:

<logger name="org.springframework.jdbc.core.JdbcTemplate" level="DEBUG" />

      

But this log only logs a wildcard query ?

without a parameter list.

Here on SO I found some answers on how to achieve parameter logging using log4j. But I don't want to switch to log4j.

So how can I get the parameter list for the JdbcTemplate using the log?

Edit

In fact, I use NamedParameterJdbcTemplate

if it matters.

+3


source to share


2 answers


try it

<logger name="org.springframework.jdbc.core.StatementCreatorUtils" level="TRACE" />



this will show log:

Setting the SQL statement parameter value: column index 1, parameter value [1234], value class [java.lang.Integer], unknown SQL type

+2


source


I usually prefer SQL query logging at the DataSource or JDBC driver level.

I am using the BoneCP DataSource / Connection Pool library which includes support for operator logging via SLF4J

and many other useful features .



If changing your DataSource / Connection Pool library is not an option, perhaps you can use log4jdbc , which works like a jdbc proxy driver that writes statements in SLF4J

before calling the actual jdbc driver that talks to the database.

0


source







All Articles