Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To display SQL statements issued by Spring’s JdbcTemplate in a Spring Boot application, set its logger to DEBUG:

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

Spring’s documented SQL-operation logger is org.springframework.jdbc.core.JdbcTemplate. Your logging backend and console appender must also allow DEBUG messages through.

Enable JdbcTemplate SQL logging in Spring Boot

Add the logger setting to the configuration file your application uses. Spring Boot supports the general form logging.level.<logger-name>=<level>; see the Spring Boot logging documentation.

Using application.properties

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

Using application.yml

logging:
  level:
    org.springframework.jdbc.core.JdbcTemplate: DEBUG

The class-level setting limits the change to JdbcTemplate’s logger. To include other Spring JDBC log messages while troubleshooting, use the broader package logger instead:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
logging.level.org.springframework.jdbc.core=DEBUG

The package setting can produce more output than the class-level setting. Choose one according to how much detail you need.

What appears in the console

The Spring Framework API documentation says that all SQL operations performed by JdbcTemplate are logged at DEBUG under the org.springframework.jdbc.core.JdbcTemplate category. The JdbcTemplate API documentation identifies that logger; the Spring JDBC reference describes SQL issued by the template as DEBUG output under its fully qualified class-name category.

Enabling that logger makes the framework’s SQL-operation messages available; it does not guarantee a single reconstructed SQL statement with every bound value substituted. If you see the SQL but not parameter values, that is not necessarily a configuration error: parameter-aware output requires a separately configured JDBC instrumentation tool.

Does the same setting work with NamedParameterJdbcTemplate?

Yes. Spring Boot can auto-configure both JdbcTemplate and NamedParameterJdbcTemplate when the required JDBC setup is present. NamedParameterJdbcTemplate uses a JdbcTemplate internally, so start with the same logger setting. See the Spring Boot SQL data-access documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When built-in logging is not enough

If you need bound-parameter visibility, execution timing, connection details, or richer formatted records, use a JDBC instrumentation layer such as a datasource proxy or P6Spy, and configure that tool’s logging separately. These tools have their own setup and behavior, so consult documentation for the specific library and version you select. More detailed SQL traces can expose sensitive values; keep them scoped to development or controlled diagnostics.

Troubleshoot missing SQL output

  1. Check that the property key is exactly logging.level.org.springframework.jdbc.core.JdbcTemplate and that its value is DEBUG.
  2. Restart the application after changing the configuration, unless your deployment explicitly supports runtime configuration refresh.
  3. Confirm that the code path uses Spring’s JdbcTemplate or NamedParameterJdbcTemplate, rather than another data-access stack.
  4. Check the active logging backend and console appender. Spring’s logging bridge selects an implementation such as Log4j 2, SLF4J, or JUL according to what is present on the classpath; the backend or appender may still filter DEBUG records. See the Spring Framework logging overview.
  5. If the output lacks the details you need, add a JDBC instrumentation tool and follow its version-specific configuration documentation.
  6. After diagnosis, remove the setting or narrow SQL DEBUG logging to avoid unnecessary output and exposure of sensitive data.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

JdbcTemplate logging is not the H2 web console

JdbcTemplate logging writes SQL-operation messages to the application’s logs. Spring Boot’s H2 web console is a separate browser-based database console intended for development, not a way to display JdbcTemplate statements in the application console. Do not enable the H2 web console in production; see the Spring Boot H2 web console documentation.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.