Although the show_ SQL option is available in hibernate, most of the displayed statements are similar.
Select * from XXX Where value =?
But sometimes we need a complete SQL statement. What should we do? You can use p6spy to complete this task.
P6spy is an open-source software that can trace any database operations generated by applications using JDBC. It is particularly suitable for monitoring the SQL statements generated by the EJB server.
Official Website: http://www.p6spy.com/
Currently, p6spy is applicable to JBoss, ATG, Orion, Jonas, Iplanet, WebLogic, websphere, resin and tomcat.
The following describes how to install p6spy on a tomcat application:
(1) download the zip package at http://www.p6spy.com/download.html
(2) decompress the p6spy. Jar spy. properties files.
(3) Put p6spy. jar into the WEB-INF/lib directory of the application, put spy. properties into the WEB-INF/classes directory
(4) Modify spy. Properties
Realdriver = com. MySQL. JDBC. DRIVER: remove the # above this line
Logfile = C:/spy. Log modify a log file name
(5) Modify hibernate. xml and set connection. driver_class to com. p6spy. Engine. Spy. p6spydriver.
(6) Restart Tomcat
(7) The spy. Log in C:/records the database access.
In fact, p6spy intercepts statment and preparedstatement to output SQL statements. JDBC can also output logs. You only need to set the driver to the driver provided by p6spy.