5

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.

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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
@FerozSiddiqui Errors will trigger exceptions to be thrown, which contain all the available details. If and how you log these is up to you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.