I have a program that updates tables in a database using prepared statements, and I'm trying to see the output of all the SQL statements that are implemented.
My research suggested P6Spy which looked great, I downloaded it, added the P6Spy.jar as a dependency in my library, modified to the spy.properties file to connect to use the oracle driver as the realdriver, added the spy.properties to my classpath, and changed the driver to "com.p6spy.engine.spy.P6SpyDriver" in my code.
It all works, the spy.log file is generated BUT it DOES NOT CONTAIN THE SQL STATEMENTS. Instead, the output in the spy.log file is :
1374244954573|-1||debug||com.p6spy.engine.common.P6SpyOptions reloading properties
1374244954578|-1||info||Using properties file: C:\Users\gboss\logging\spy.properties
1374244954579|-1||info||No value in environment for: getStackTrace, using: false
1374244954579|-1||info||No value in environment for: getDeregisterDrivers, using: false
1374244954579|-1||info||No value in environment for: getUsePrefix, using: false
1374244954579|-1||info||No value in environment for: getExecutionThreshold, using: 0
1374244954579|-1||info||No value in environment for: getAutoflush, using: true
1374244954579|-1||info||No value in environment for: getExclude, using:
1374244954579|-1||info||No value in environment for: getExcludecategories, using: info,debug,result,batch
1374244954579|-1||info||No value in environment for: getFilter, using: true
1374244954579|-1||info||No value in environment for: getInclude, using:
1374244954579|-1||info||No value in environment for: getIncludecategories, using:
1374244954579|-1||info||No value in environment for: getLogfile, using: c:/spy.log
1374244954579|-1||info||No value in environment for: getAppender, using: com.p6spy.engine.logging.appender.FileLogger
1374244954579|-1||info||No value in environment for: getRealdriver, using: oracle.jdbc.driver.OracleDriver
1374244954579|-1||info||No value in environment for: getRealdriver2, using:
1374244954580|-1||info||No value in environment for: getRealdriver3, using:
1374244954580|-1||info||No value in environment for: getAppend, using: true
1374244954580|-1||info||No value in environment for: getSpydriver, using: com.p6spy.engine.spy.P6SpyDriver
1374244954580|-1||info||No value in environment for: getDateformat, using:
1374244954580|-1||info||No value in environment for: getDateformatter, using: null
1374244954580|-1||info||No value in environment for: getStringmatcher, using: com.p6spy.engine.common.SubstringMatcher
1374244954580|-1||info||No value in environment for: getStringMatcherEngine, using: com.p6spy.engine.common.SubstringMatcher@13aaa14a
1374244954580|-1||info||No value in environment for: getStackTraceClass, using:
1374244954580|-1||info||No value in environment for: getSQLExpression, using: null
1374244954580|-1||info||No value in environment for: getReloadProperties, using: false
1374244954580|-1||info||No value in environment for: getReloadPropertiesInterval, using: 60
1374244954580|-1||info||No value in environment for: getJNDIContextFactory, using: null
1374244954580|-1||info||No value in environment for: getJNDIContextProviderURL, using: null
1374244954580|-1||info||No value in environment for: getJNDIContextCustom, using: null
1374244954580|-1||info||No value in environment for: getRealDataSource, using: null
1374244954580|-1||info||No value in environment for: getRealDataSourceClass, using: null
1374244954580|-1||info||No value in environment for: getRealDataSourceProperties, using: null
does anyone have experience using P6Spy and know what the issue is? I've read that the spy.log is just supposed to generate the sql statements after doing all the things I did and running the program, so I'm pretty confused here
EDIT -- The database was updated by the way, so the SQL statements did go through and update the database
This is typically caused by the P6SpyDriver being registered with DriverManager after your real JDBC driver is registered. P6Spy 1.3 did not require you to change the JDBC URL. When the application code (or app server) tries to get a suitable driver from DriverManager, it cycles through the registered drivers to find the first one the handles the URL. If P6SpyDriver is not registered before the real driver, then it will not be used.
There are two ways to fix this problem:
This will cause P6Spy to unregister the real driver and then reregister it. This will cause DriverManager to use P6SpyDriver. However, with Java 6+ you must make sure that the driver class you have listed for the real driver matches the one that will be autoregistered. You can get this class name from META-INF/services/java.sql.Driver. If that file does not exist in the JAR file for the JDBC driver, then it does not support auto registeration.
This will ensure that the P6SpyDriver will be used regardless of the order in which the drivers are loaded. This is actually the most reliable way...
See http://p6spy.github.io/p6spy/1.3/configandusage.html for the various configuration options available with 1.3.