How to print JPA and jdbcTemplate SQL logs in SpringBoot apps?
1. The purpose of this post
This demo shows how to print SQL logs of your DAO when using SpringBoot apps.
2. Environments
- SpringBoot 1.x and 2.x
- Java 1.8+
3. JPA solution
Just add this to your application.properties
:
Then you would get this:
You can find detailed documentation of this setting in Data Access of SpringBoot Reference.
4. JdbcTemplate solution
Just add this to your application.properties
:
Then you would get this:
Summary
This post explained how to print SQL logs for both JPA and jdbcTemplate
in SpringBoot applications. By configuring the application.properties
file, you can easily enable SQL logging for debugging and monitoring purposes. For JPA, setting spring.jpa.show-sql=true
displays Hibernate-generated SQL queries, while for jdbcTemplate
, setting the logging level to TRACE
captures SQL execution logs. These configurations are essential for developers to understand and optimize database interactions in SpringBoot applications.
Final Words + More Resources
My intention with this article was to help others who might be considering solving such a problem. So I hope that’s been the case here. If you still have any questions, don’t hesitate to ask me by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!