spring boot project, used JdbcTemplate
, and want to show sql which is executed, the configuration is as below
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
but nothing output, it seems above configuration only support spring data jpa
, So I'd like to know does exist some manner could show sql even used JdbcTemplate
directly?
Spring Boot supports H2 (an in-memory relational database engine) and automatically creates a connection. Because we use spring-jdbc , Spring Boot automatically creates a JdbcTemplate . The @Autowired JdbcTemplate field automatically loads it and makes it available.
There are many options available for executing native sql with JdbcTemplate . The linked documentation contains plenty of methods that take native sql, and usually some sort of callback handler, which will accomplish exactly what you are looking for.
There is a reason why the property is named spring.jpa
something: it is to indicate you that it relates to JPA in some form.
If you're using JdbcTemplate
, you're not using JPA hence that property can't have any effect. You can enable logging for the org.springframework.jdbc.core.JdbcTemplate
class
logging.level.org.springframework.jdbc.core.JdbcTemplate=debug
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With