1 db.driverClassName = com.cownew.JDBMonitor.jdbc.DBDriver
db.url = listenerconfig=c:/config.xml:url=
2 config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<Listeners>
<Listener class="com.cownew.JDBMonitor.listenerImpl.FileDBListener" arg="c:/log.txt"/>
<Listener class="com.cownew.JDBMonitor.listenerImpl.ConsoleDBListener" arg=""/>
<Listener class="com.cownew.JDBMonitor.listenerImpl.SocketDBListener" arg="9527"/>
<Listener class="com.cownew.JDBMonitor.listenerImpl.DataBaseDBListener"
arg="dburl=com.microsoft.jdbc.sqlserver.SQLServerDriver;user=sa;password=sa;logtable=T_Log_SQLLog"/>
</Listeners>
<JdbcDrivers>
<JdbcDriver class="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
</JdbcDrivers>
</config>
T_Log_SQLLog FID FBeginTime FEndTime FSQLType FParameters
运行"java -classpath jdbmonitor.jar com.cownew.JDBMonitor.listenerImpl.sckListenerClient.SocketConsoleClient" 来启动SocketConsoleClient ,运行"java -classpath jdbmonitor.jar com.cownew.JDBMonitor.listenerImpl.sckListenerClient.SocketSwingClient" 启动SocketSwingClient
public void init(String arg);
public void logSql(SQLInfo info);
com.cownew.JDBMonitor.commo. IDBListener
# <bean id="dataSourceTarget" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
# <property name="driverClassName">
# <value>com.sybase.jdbc2.jdbc.SybDriver</value>
# </property>
# <property name="url">
# <value>jdbc:sybase:Tds:192.168.0.2:6100/db</value>
# </property>
# <property name="username">
# <value>usr</value>
# </property>
# <property name="password">
# <value>pwd</value>
# </property>
# </bean>
# <bean id="dataSource" class="com.p6spy.engine.spy.P6DataSource"
# destroy-method="close">
# <constructor-arg>
# <ref local="dataSourceTarget"/>
# </constructor-arg>
# </bean>
1、配置待测试应用系统
添加P6Spy.jar,并修改应用的数据库驱动为“com.p6spy.engine.spy.P6SpyDriver” 。
2、配置 P6Spy
将spy.properties放在应用的classes目录下,然后将原来的JDBC驱动类配置到P6spy的配置文件 spy.properties中的realdriver项就可以了。注意尽量不要修改其他配置,尤其是其中的logger配置
其格式为:
1124430077712|266|1|statement||select count(*) as nodeTotalNum from wr_Activity where procinstid= ?| select count(*) as nodeTotalNum from wr_Activity where procinstid= 1
所有的JDBC驱动都实现java.sql.Driver接口,此接口有两个重要方法:Connection connect(String url, java.util.Properties info),boolean acceptsURL(String url)。
有个DriverManager类,它有一个重要方法,registerDriver(java.sql.Driver driver)
DriverManager.getConnection("jdbc:……")----------acceptsURL
DBDriver、DBConnection、DBStatement、DBPreparedStatement