log4jdbc sql监控
log4jdbc
可以和sl4j 很好的整合 并输出日志
可以捕获程序最终调用jdbc时的一些状态
可以获取完整的sql语句,包括注入?的参数值 sql语句可以直接运行
可以获取sql语句的执行耗时
可以获取jdbc获取结果集时的详细信息过程
可以获取jdbc连接的信息
log4jdbc3-1.2beta2.jar 支持 JDK 1.4 , JDK 1.5
log4jdbc4-1.2beta2.jar 支持 JDK 1.6 , JDK 1.7
实施过程:
只需要将jar添加到项目
将jdbc配置文件的
jdbc.driverClassName = net.sf.log4jdbc.DriverSpy
jdbc.url = jdbc:log4jdbc:oracle:thin:@venus:1521:kthis
log4jdbc会自己去寻找适合的oracle jdbc驱动
在sl4j配置文件
<logger name="jdbc.sqlonly" additivity="false"></logger>
<logger name="jdbc.sqltiming" additivity="true"></logger>
<logger name="jdbc.audit" additivity="false"></logger>
<logger name="jdbc.resultset" additivity="false"></logger>
日志文件中的显示:
5. SELECT APT.APPOINTMENT_ID, APT.APPOINTMENTRESOURCEMSTR_ID, APT.APPOINTMENT_TYPE, APT.APPIONTMENT_STATUS,
APT.APPOINTMENT_DESC, APT.APPOINTMENT_DESC_LANG1, APT.APPOINTMENT_BEGINDATETIME, APT.APPOINTMENT_ENDDATETIME,
APT.REMARKS, RAPT.REGNAPPOINTMENT_ID, RAPT.RESOURCESCHEME_ID, RAPT.REGN_APPOINTMENT_NO, (SELECT
P.PERSON_NAME FROM PERSON P, PATIENT PT WHERE PT.PATIENT_ID = RAPT.PATIENT_ID AND P.PERSON_ID
= PT.PERSON_ID) PATIENT_NAME FROM APPOINTMENT APT LEFT JOIN REGNAPPOINTMENT RAPT ON APT.APPOINTMENT_ID
= RAPT.APPOINTMENT_ID WHERE APT.DEFUNCT_IND = 'N' AND APT.APPOINTMENTRESOURCEMSTR_ID = 573
ORDER BY APT.APPOINTMENT_BEGINDATETIME {executed in 19 msec}