继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

jboss:跟踪所有sql语句及sql参数

繁星coding
关注TA
已关注
手记 221
粉丝 10
获赞 54

默认情况下,hibernate/JPA 在server.log中记录的SQL语句,参数都是用?代替的,这样不太方便. 网上留传的p6spy在最新的jboss上(EAP 6.0+版本)貌似已经不起作用了(至少我没弄成功过)

 

幸好,Jboss已经自带了jdbc监控功能,开启步骤如下:

1、standalone.xml中增加

1             <logger category="jboss.jdbc.spy">
2                 <level name="DEBUG"/>
3             </logger>

2、所有的DataSouce节点上,增加spy="true",参考下面这样:

1 <datasource jta="false" jndi-name="java:/XE" pool-name="XE" enabled="true" spy="true" use-ccm="false">
2                     <connection-url>jdbc:oracle:thin:@localhost:1521:XE</connection-url>
3                     <driver-class>oracle.jdbc.OracleDriver</driver-class>
4 ...

好了,server.log中就会记录详细的sql信息,类似下面这样:

...

11:26:28,788 INFO  [stdout] (http-localhost/127.0.0.1:8080-2) Hibernate:
11:26:28,788 INFO  [stdout] (http-localhost/127.0.0.1:8080-2)     /* insert org.jboss.as.quickstart.hibernate4.model.Member
11:26:28,788 INFO  [stdout] (http-localhost/127.0.0.1:8080-2)         */ insert
11:26:28,788 INFO  [stdout] (http-localhost/127.0.0.1:8080-2)         into
11:26:28,788 INFO  [stdout] (http-localhost/127.0.0.1:8080-2)             MemberHibernate4Demo
11:26:28,788 INFO  [stdout] (http-localhost/127.0.0.1:8080-2)             (address, email, name, phone_number, id)
11:26:28,788 INFO  [stdout] (http-localhost/127.0.0.1:8080-2)         values
11:26:28,788 INFO  [stdout] (http-localhost/127.0.0.1:8080-2)             (?, ?, ?, ?, ?)
11:26:28,788 DEBUG [jboss.jdbc.spy] (http-localhost/127.0.0.1:8080-2) java:/XE [PreparedStatement] setString(1, shanghai,China)
11:26:28,788 DEBUG [jboss.jdbc.spy] (http-localhost/127.0.0.1:8080-2) java:/XE [PreparedStatement] setString(2, jimmy.yang@jboss.org)
11:26:28,789 DEBUG [jboss.jdbc.spy] (http-localhost/127.0.0.1:8080-2) java:/XE [PreparedStatement] setString(3, jimmy)
11:26:28,789 DEBUG [jboss.jdbc.spy] (http-localhost/127.0.0.1:8080-2) java:/XE [PreparedStatement] setString(4, 13916752129)
11:26:28,789 DEBUG [jboss.jdbc.spy] (http-localhost/127.0.0.1:8080-2) java:/XE [PreparedStatement] setLong(5, 4)

...

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP