Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring boot could show sql even use JdbcTemplate directly

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?

like image 447
zhuguowei Avatar asked Mar 08 '16 04:03

zhuguowei


People also ask

Can we use JdbcTemplate in Spring boot?

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.

Does JdbcTemplate support execution of SQL native queries?

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.


Video Answer


1 Answers

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
like image 159
Stephane Nicoll Avatar answered Oct 14 '22 06:10

Stephane Nicoll