采用p6spy完整显示hibernate的SQL语句
虽然在hibernate中有show_sql选项,但是显示出来的语句大多类似
select * from xxx where value=?
但是有时候我们需要得到完整的SQL语句,怎么办呢?使用P6SPY就可以完成这个任务
p6spy是一个开源软件,它可以跟踪任何使用jdbc的应用产生的数据库操作。特别适合于监控ejb服务器产生的 sql statements。
官方网址:http://www.p6spy.com/
目前p6spy 适用的应用服务器包括jboss, atg, orion, jonas, iplanet, weblogic, websphere, resin and tomcat.
下面我介绍一下p6spy在tomcat应用程序上安装的步骤:
(1)http://www.p6spy.com/download.html ,下载zip包
(2)解压出p6spy.jar spy.properties两个文件
(3)将p6spy.jar 放入应用程序的WEB-INF/lib目录,将spy.properties放入WEB-INF/classes目录
(4)修改spy.properties
realdriver =com.mysql.jdbc.Driver 将这行前面的#去掉
logfile = c:/spy.log 修改一个你需要的日志文件名
(5)修改hibernate.xml,修改connection.driver_class的值为com.p6spy.engine.spy.P6SpyDriver
(6)重启tomcat
(7)这样在c:/下的spy.log记录了数据库的访问情况。
驱动程序加载先后的问题解决
如果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,重新运行即可。
5.在spring 配置文件中配置如下:
<!-- P6SPY dataSource target -->
<bean id = "dataSourceTarget" class = "org.spring framework.jdbc.datasource.DriverManagerDataSource" >
<property name = "driverClassName" value = "oracle.jdbc.OracleDriver" />
<property name = "url" value = "jdbc:oracle:thin:@localhost:1521:testdb" />
<property name = "username" value = "tet" />
<property name = "password" value = "test" />
</bean > <!-- dataSource -->
<bean id = "dataSource4develop" class = "com.p6spy .engine.spy.P6DataSource" destroy-method = "close" >
<constructor-arg >
<ref local = "dataSourceTarget" />
</constructor-arg >
</bean >
采用p6spy完整显示hibernate的SQL语句的更多相关文章
- 显示hibernate的sql语句
<property name="show_sql">true</property> <property name="format_sql&q ...
- 在hibernate中用sql语句
在hibernate中用sql语句,语句是createSQLquery 查出来的是,一列或者多列的数据,要将其转化为对象,有两种方式, 对于已经被hibernate所管理的实体类,在后面加.adden ...
- 通过Log4j的DEBUG级别来显示mybatis的sql语句
为了更加方便调试sql语句,需要显示mybatis的sql语句. 网络上的一般方式都是通过log4j来实现,但是很多都有问题. 经过实验,以下代码能够保持正常:(只显示myb ...
- Hibernate执行sql语句
Hibernate执行sql语句:BasicServiceImpl basicServiceImpl = new BasicServiceImpl();String hql = "selec ...
- 控制台打印Hibernate的SQL语句显示绑定参数值
问题? 使用Hibernate提供的show_sql内置属性true只能输出类似于下面的SQL语句:Hibernate: insert into user(name,password) value ...
- Hibernate使用sql语句实现多表关联查询
/** * <查找list> * * @return 返回页面需要显示的数据 */ @SuppressWarnings("unchecked") public List ...
- Hibernate输出SQL语句以便调试
配置方法:1.打开hibernate.cfg.xml文件编辑界面,在Properties窗口处,点击Add按钮,选择Show_SQL参数,输入值为True. *另外,如果按照同样的步骤,分别加入以下参 ...
- Hibernate执行SQL语句实现查询修改功能!
今天玩Hibernate时突然就想写写SQL语句查询... DAO : //查询 public List<?> createSqlQueryList(final String queryS ...
- Hibernate 执行sql语句返回yntax error: syntax error, expect LPAREN, actual NOT not
hibernate自动创建表时提示 : ERROR: sql injection violation, syntax error: syntax error, expect LPAREN, actu ...
随机推荐
- JavaScript判断字符串能否转化为数字
判断一个字符串能否转化为数字 我们常常使用parseInt函数. 不过该函数的适用范围是很小的. 一般说来对于 如下类似 var myStr = "123hello"; 使用par ...
- 【mysql】mysql分表和表分区详解
为什么要分表和分区? 日常开发中我们经常会遇到大表的情况,所谓的大表是指存储了百万级乃至千万级条记录的表.这样的表过于庞大,导致数据库在查询和插入的时候耗时太长,性能低下,如果涉及联合查询的情况,性能 ...
- ajax用户名案例(重点)
要求:失去焦点时如下效果 主页代码 <body> 用户名:<input type="text" id="a" /><div i ...
- ajax语法
js语言功能比较强大,但不能访问数据库 ajax来补充这一缺陷 特点:输出不用刷新页面,条件查询数据显示页面上一般不用它,因为需要造很多表格不如用嵌入php代码方式简单 ajax语法: $.ajax( ...
- HackerRank "Favorite sequence"
Typical topological sorting problem .. why is it 'difficult'? #include <iostream> #include < ...
- Python 上传和更新函数模块到PyPI
1. update setup.py from distutils.core import setup setup( name = 'iamericnester', version = '1.4.0' ...
- OpenCV中Delaunay三角网算法例子
#include <opencv2/opencv.hpp> #include <vector> using namespace cv; using namespace std; ...
- smartgit document Rebase
The Rebase command allows you to apply commits from one branch to another. Rebase can be viewed as m ...
- Form_Form Builder本地部署运行的实现(案例)
2014-08-09 Created By BaoXinjian
- OAF_EO系列3 - Initialize详解和实现(案例)
2014-06-14 Created By BaoXinjian