3

If you want to see what SQL statements Spring Data JDBC is executing, how would you do that? Since it uses bind variables, I also want to see their values in the logs.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348

1 Answers1

3

Spring Data JDBC uses a JdbcTemplate to execute all SQL statements. So you really need to configure logging for that.

The statements itself are logged by the template itself with DEBUG level. To see these you have to set the log level of org.springframework.jdbc.core.JdbcTemplate to DEBUG.

The arguments for the bind variables are logged by org.springframework.jdbc.core.StatementCreatorUtils on TRACE level.

How you configure those depends on your project setup. You can use the configuration options of Log4J, Logback or whatever logging implementation you are using. Or if you happen to use Spring Boot the following rows in the application.properties should do the trick.

logging.level.org.springframework.jdbc.core.StatementCreatorUtils=TRACE
logging.level.org.springframework.jdbc.core.JdbcTemplate=DEBUG

Or simply

logging.level.org.springframework.jdbc.core = TRACE

If you don't mind possibly getting some extra output.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
  • how to do this configuration with logback. I can only see the SQL generated but not errors inside sql. for e.g column not found – Feroz Siddiqui Jan 15 '23 at 15:31