弄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 :-)
一切尽在眼前了吧?
当然,p6spy 和 sql profiler 能做的不止这些,sql profiler还能根据你的query来帮你生成建立合适的index功能等等。
分享到:
相关推荐
hibernate实现动态SQL查询,通过XML配置SQL,FREEMARKER 解析,生成要执行的SQL
NULL 博文链接:https://elfasd.iteye.com/blog/1770847
使用hibernate对sqlserver 2005进行增删改查
hibernate中使用sql 而不是hql语句
让hibernate输出sql语句参数配置.doc
模仿Hibernate生产SQL语句,使用Java反射
hibernate常见错误解决方案
Hibernate 显示完整sql的配置工具,配置好后在Console会输出不带?的sql语句,方便调试。
不错的分页(Hibernate+sqlserver2000分页)值得大家一看。
虽然在hibernate中有show_sql选项,但是显示出来的语句大多类似 select * from xxx where value=? 但是有时候我们需要得到完整的SQL语句,怎么办呢?使用P6SPY就可以完成这个任务
hibernate执行原生sql语句
ssh spring+stuts+hibernate+sql server 中文乱码解决方案_lj管用.txt
基于JavaWeb实现的图书管理系统(struts+spring+hibernate+SQL Server) 基于JavaWeb实现的图书管理系统(struts+spring+hibernate+SQL Server) 基于JavaWeb实现的图书管理系统(struts+spring+hibernate+SQL Server) ...
基于spring实现的网上订餐系统(struts+spring+hibernate+SQL Server) 基于spring实现的网上订餐系统(struts+spring+hibernate+SQL Server) 基于spring实现的网上订餐系统(struts+spring+hibernate+SQL Server) 基于...
Hibernate提供的查询接口或其方法 hibernate综合查询解决方案
Hibernate+本地SQL查询SQLQuery宣贯.pdf
NULL 博文链接:https://ynp.iteye.com/blog/2007053
使用Hibernate编写通用数据库操作代码
NULL 博文链接:https://gghaomm.iteye.com/blog/1763082