JDBC监听器-P6Spy

本文介绍了如何使用P6Spy监听JDBC对数据库的修改,详细阐述了下载、安装、配置及结果查看的流程。通过在工程中引入p6spy.jar并配置相关属性,可以实现对SQL的监听和记录,日志文件默认保存为spy.log。此外,还提到了P6Spy与Hibernate的集成使用。
摘要由CSDN通过智能技术生成

JDBC监听器-P6Spy

sf2gis@163.com

2015年12月7日

 

1  目标:监听JDBC对数据库的修改,并显示相关的SQL。

2 原理:封装JDBC驱动,监听JDBC调用。

3 流程:下载,安装,配置,结果查看。

参考:http://www.iteye.com/topic/4143

3.1 下载:从SourceForge中下载p6spy-install.jar。

http://sourceforge.net/projects/p6spy/?source=typ_redirect

注意:不要下载github中的zip。

3.2 安装:解压后,将pyspy.jar复制到工程的buildpath。将spy.properties复制到src目录。

3.3 配置:配置spy.properties和hibernate。

基本上保持spy.properties的默认值,只需修改

真正的驱动:realdriver=com.mysql.jdbc.Driver。

注销驱动注册(如果注册早了,会使用真正的驱动,无法监听):deregisterdrivers=true

//spy.properties

#################################################################

# P6Spy Options File                                            #

# See documentation fordetailed instructions                   #

#################################################################

 

#################################################################

# MODULES                                                      #

#                                                              #

# Modules provide the P6Spyfunctionality.  If a module, such   #

# as module_log is commentedout, that functionality will not   #

# be available.  If it is not commented out (if it isactive),  #

# the functionality will beactive.                             #

#                                                               #

# Values set in Modulescannot be reloaded using the            #

# reloadpropertiesvariable.  Once they are loaded, theyremain #

# in memory until theapplication is restarted.                #

#                                                               #

#################################################################

 

module.log=com.p6spy.engine.logging.P6LogFactory

#module.outage=com.p6spy.engine.outage.P6OutageFactory

 

#################################################################

# REALDRIVER(s)                                                #

#                                                              #

# In your application serverconfiguration file you replace the #

# "real driver"name with com.p6spy.engine.P6SpyDriver. This is #

# where you put the name ofyour real driver P6Spy can find and #

# register your real driverto do the database work.            #

#                                                              #

# If your application usesseveral drivers specify them in      #

# realdriver2,realdriver3.  See the documentation formore     #

# details.                                                     #

#                                                              #

# Values set in REALDRIVER(s)cannot be reloaded using the      #

# reloadpropertiesvariable.  Once they are loaded, theyremain #

# in memory until theapplication is restarted.                #

#                       

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

弗里曼的小伙伴

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值