天天看點

P6SPY和SQL Profiler使用

 弄hibernate時,想顯示sql語句,可以設定show_sql為true來達到這個目的,但是參數值全是像PreparedStatement一樣,用?來代替的。

用p6spy可以達到顯示的那些參數原值的目的,但可讀性差。可以利用SQL Profiler來處理這個事情。

p6spy: http://www.p6spy.com

SQL Profile: http://www.jahia.net/jahia/page597.html

p6spy安裝:

* 将p6spy.jar放到WEB-INF/lib目錄下,将spy.properties放到WEB-INF/classes目錄下。

* 修改你 原有 JDBC Driver為:com.p6spy.engine.spy.P6SpyDriver

* 修改 spy.properties 中的 realdriver 值為 原有 的JDBC Driver,比如我的是:com.mysql.jdbc.Driver

* 完成,運作web server。

我的日志記錄産生在 %TOMCAT_HOME%/bin下,此log位置可以能過修改 logfile  = x:/x_dir/spy.log 來控制

打開看看,看裡面的日志是不是看起來比較不爽?下面我們安裝SQL Profiler來讓自已的視線爽一點。

SQL Profiler安裝:(須p6spy成功安裝)

* 将SQL Profiler自帶的spy.properties覆寫原來的classes目錄下檔案

* 修改現在spy.properties中realdriver 值為 原有 的JDBC Driver

看後看看readme注意這幾句 ^__^ :

1. Start the GUI

2. Start the webapp, in starts doing some JDBC requests we will ignore

3. Press the "reset" button on the GUI

4. Make a request to the webapp

5. Press the "pause" button after the request has finished executing

6. Press the "report" button to save profiling results as a CSV file

* 我們先用java -jar sqlprofiler.jar 運作 sql profiler

* 然後啟動web server