To view SQL queries sent to DB we usually use showSql
parameter:
spring.jpa.showSql=true
It allows us to see the statement body but not its parameters:
insert into master (id, version, name) values (null, ?, ?)
And especially we don't see a result of the query.
Is there a way to see SQL statement, its parameters and result in the application log?
JDBC logging
With log4jdbc-spring-boot-starter we can easily log all JDBC statements, their parameters and results in Spring Boot/Spring Data JPA projects.
For example, when we perform some JPQL query in our application:
then we see the following SQL query with its parameter in the application log:
And its result in the table form:
To use this starter we have to add its dependency to our project:
and add these parameters to
application.properties
:Additionally, we can add these log4jdbc parameters to get the output in one line: