Can't achieve working with p6Spy

僤鯓⒐⒋嵵緔 提交于 2019-12-02 10:43:11

问题


I've tried two methods for adding p6Spy feature to my spring used project.

Route I,

http://templth.blogspot.com.tr/2004/11/integrate-p6spy-with-spring.html I changed my driver with com.p6spy.engine.spy.P6SpyDriver and added realdriver realdriver=com.ibm.db2.jcc.DB2Driver into spy.properties file.

But somehow my realdriver is being registered before p6spy driver com.ibm.db2.jcc.DB2Driver is a real driver in spy.properties, but it has been loaded before p6spy. p6spy will not wrap these connections.Either prevent the driver from loading, or try setting 'deregisterdrivers' to true in spy.properties

Using :p6spy: prefix doesn't work for me. It says can't establish connection with that url.

So,I chose setting this deregisterdrivers=true in property file. This time I get sql in log file but can't execute sqls. I'm able to execute sql in another sql editor. It seemed real connection went and a dummy one came.

Route II, We use spring. So I've tried this method. Giving datasource explicitly to p6Spy. But this time spring complained of multiple java.sql.DataSource instance. Both com.firm.BasicDataFill and com.p6spy.engine.spy.P6DataSource implements DataSource. Spring can't obtain a singleton.

http://templth.blogspot.com.tr/2004/11/integrate-p6spy-with-spring.html

<bean id="dataSource" lazy-init="true"
    class="com.firm.BasicDataFill">
    <property name="driverClassName" value="${database.connection.driver_class}" />
    <property name="username" value="${database.connection.username}" />
    <property name="password" value="${database.connection.password}" />
    <property name="url" value="${database.connection.url}" />
       ...
    <property name="accessToUnderlyingConnectionAllowed" value="true" />                                
</bean>

<!-- bean id="myDataSource" class="com.p6spy.engine.spy.P6DataSource">
    <constructor-arg>
        <ref local="dataSource"/>
    </constructor-arg>
</bean-->

Finally, I discovered p6spy v1.3 and 2.4.1 settings vary. Do you have any suggestion for a spring based application.


回答1:


I would recommend starting with the latest version of P6Spy 2.x. You should also REPLACE your spy.properties file with the default version for 2.X which is documented here. Depending on your application server, you might need to set the 'realdriver' setting in spy.properties to include 'com.ibm.db2.jcc.DB2Driver'. However, this is only needed when you are using an application server that prevents the automatic registration of JDBC Drivers.

To use P6Spy with Spring, the easiest method is to wrap your current data source bean with P6SpyDataSource as discussed here. The example in that answer shows a JNDI data source being wrapped but it can be used to wrap any data source. Note: If you are wrapping the data source is P6SpyDataSource, you do NOT need to modify the JDBC URL.

If you continue to have problems, please add a bit more information to your question. The following information would be helpful in troubleshooting:

  1. The version of P6Spy being used
  2. The contents of spy.properties
  3. The definition of your datasource (including app server config if using JNDI)
  4. The type of app server and version being used
  5. Stacktrace containing whatever error you might have received.



回答2:


Have a look at Log4jdbc it'll do the job https://code.google.com/p/log4jdbc/



来源:https://stackoverflow.com/questions/31337283/cant-achieve-working-with-p6spy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!