“Nearly 80 to 85 percent of database performance problems arise from the application database's design or the application's own code. Good transaction throughput requires an application designed from the database up, with performance and scalability in mind.”
----DB2 Magazine
一、P6Spy的安裝與使用
1、從 http://www.p6spy.com/ 下載P6Spy的檔案包,也可以下載它的源檔案包來研究;
2、把P6Spy的jar包p6spy.jar放到classpath中,如果是Web應用程式則放在YourWebApp/WEB-INF/lib/目錄下;
3、把spy.properties放到classes目錄下,如果是webapp就放在YourWebApp/WEB-INF/classess/目錄下,記得不是lib/目錄
4、修改你程式的資料庫驅動名稱為P6Spy的驅動程式名稱com.p6spy.engine.spy.P6SpyDriver其它的都不用更改;
5、開啟spy.properties檔案,把realdriver的值改為你的程式的資料庫驅動名稱;
6、運行你的應用程式或Web應用程式,可以在spy.log裡看到監測到的sql詳細記錄資訊了。
7、驅動程式載入先後的問題解決
如果spy.log裡出現
你的程式的資料庫驅動名稱 is a real driver in spy.properties, but it has been loaded before p6spy. p6spy will not wrap these connections. Either prevent the driver from loading, or try setting 'deregisterdrivers' to true in spy.properties
請把spy.properties檔案裡的deregisterdrivers=false改為deregisterdrivers=true,重新運行即可。