I've Spring Boot Application that uses Spring data JPA and MySQL. With setting SQL properties in application.yml file, I can see the sql but I need to print the values with SQL. How can I achieve that?
4 Answers
You can follow the steps given to achieve this:
Add following to pom.xml
<dependency> <groupId>com.github.gavlyukovskiy</groupId> <artifactId>p6spy-spring-boot-starter</artifactId> <version>1.6.3</version> </dependency>
2. If you are using Eclipse/IntelliJ, Add Program arguments in Run -> Edit Configuration
-Dspy.properties=/PathToP6SpyDir/spy.properties
3. Add following to spy.properties file:
driverlist=com.mysql.jdbc.Driver
appender=com.p6spy.engine.spy.appender.Slf4JLogger
logMessageFormat=com.p6spy.engine.spy.appender.CustomLineFormat
customLogMessageFormat=time %(executionTime)|con %(connectionId)|%(sqlSingleLine)
2 Comments
Ashish
What is it the answer by @TechGeek did not resolve. Is this solution specific to your case. Most people wont be allowed to use third party libraries as in this solution. Can you highlight if the answer by TechGeek did not help you and why?
Sanjay Amin
Ashish, Thanks for bringing this. The one I suggested helped me to find real sql like statements while using JPA . Answer from @TechGeek also works with giving extracted value for each field. The one I suggested, I would recommend only for local or dev env. and not for prod env.