JDBC监听器-P6Spy
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. #
# &n

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

被折叠的 条评论
为什么被折叠?



