使用P6Spy打印Resin执行的SQL语句

 

系统开发时,经常要看程序执行的SQL。使用Hibernate开发的系统设置了show_sql=true后,只能看到预编译的SQL语句,看不到传到SQL的具体参数。如:

 

select xnxqdm0_.XNXQM as XNXQM763_0_, xnxqdm0_.XNXQMC as XNXQMC763_0_ from CODE_XNXQDMB_V xnxqdm0_ where xnxqdm0_.XNXQM=?

 使用开源软件P6Spy,能把SQL所用的具体参数打印出来,如:

 

 

07-24-13 09:40:13:439|1|22|statement|select xnxqdm0_.XNXQM as XNXQM763_0_, xnxqdm0_.XNXQMC as XNXQMC763_0_ from CODE_XNXQDMB_V xnxqdm0_ where xnxqdm0_.XNXQM=?|select xnxqdm0_.XNXQM as XNXQM763_0_, xnxqdm0_.XNXQMC as XNXQMC763_0_ from CODE_XNXQDMB_V xnxqdm0_ where xnxqdm0_.XNXQM='2011-2012-1'

 P6Spy包含一个jar文件以及spy.properties配置文件。下面以在Linux系统的Resin3.0.28中配置Oracle链接为例介绍配置过程。

 

<database>
    <jndi-name>jdbc/OracleDB</jndi-name>
        <driver type="oracle.jdbc.OracleDriver">

 改成

 

 

<database>
  <jndi-name>jdbc/OracleDB</jndi-name>
     <driver type="com.p6spy.engine.spy.P6SpyDriver">
  • 修改spy.properties如:

 

module.log=com.p6spy.engine.logging.P6LogFactory
realdriver=oracle.jdbc.OracleDriver
realdriver2=oracle.jdbc.driver.OracleDriver
realdriver3=
deregisterdrivers=true
executionthreshold=
outagedetection=false
outagedetectioninterval=
include =
exclude =
sqlexpression =
filter=false
trace = true
autoflush = true
dateformat=MM-dd-yy HH:mm:ss:SS
includecategories=statement,batch,commit,rollback
#error,info,debug,statement,batch,commit,rollback,result
excludecategories=
stringmatcher=
stacktrace=false
stacktraceclass=
reloadproperties=false
reloadpropertiesinterval=60
useprefix=false
appender=com.p6spy.engine.logging.appender.StdoutLogger
#appender=com.p6spy.engine.logging.appender.Log4jLogger
#appender=com.p6spy.engine.logging.appender.FileLogger
logfile = c:\spy.log
append=true
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout

log4j.logger.p6spy=INFO,STDOUT

 

 

  • 以上修改做完后,重启应用,即可看到P6Spy打印的带参数内容的SQL语句。值得注意的是realdriver得配置两个才有效果。
realdriver=oracle.jdbc.OracleDriver
realdriver2=oracle.jdbc.driver.OracleDriver

 

你可能感兴趣的:(java,resin,P6spy,SQL执行日志)