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. #
#