aspose file tools*
The moose likes Other Open Source Projects and the fly likes P6spy does not create spy.log for stand-alone Java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "P6spy does not create spy.log for stand-alone Java program" Watch "P6spy does not create spy.log for stand-alone Java program" New topic
Author

P6spy does not create spy.log for stand-alone Java program

Sam Gehouse
Ranch Hand

Joined: Jul 21, 2003
Posts: 281
I am trying to use p6spy (downloaded from the site itself) for logging sql for a stand-alone Java program (main class that calls data access class).
I have done the following configurations:
1. Placed p6spy.jar in the classpath of the project.
2. Places spy.properties is in the class path. In fact, spy.properties is under the same package as that of Java main class that I call at this time.

The Java program at this time only queries database using a single select from a single DB2 database table. The Java program successfully executes the query (prepared stamenet, usses iBATIS and Spring) and returns query result and also terminates successfully (without any exception).

However, the spy.log file does not get created.

Any help will be appreciated.

Following is the configuration of spy.properties.


[ October 28, 2008: Message edited by: Martijn Verburg ]
Sam Gehouse
Ranch Hand

Joined: Jul 21, 2003
Posts: 281
It seems that I am not being able to use p6spy at all. My stand-alone Java program looks up user name, password, driver etc. from a separate XML file (myapp.xml) using Spring.

I was under the impression that if I added p6spy.jar and spy.properties in classpath with proper configurations, I should be able to use p6spy.

But as you said, it seems that I am not using p6spy. When running the program, the program ignores p6spy totally.

I have a separate file (myapp.xml) which specifies driver, user name, password etc. My app loads myapp.xml using Spring ApplicationContext and runs it successfully.

Nowhere in my program I have mentioned spy.properties file. The only thing that I have done is, adding p6spy.jar file and spy.properties in classpath. I thought that will do the magic.

Is there anything else I need to to use p6spy?

My driver (Java main) class loads myapp.xml using Spring as:

ApplicationContext ctx = new ClassPathXmlApplicationContext("myapp.xml");

myapp.xml looks like:

[ October 28, 2008: Message edited by: Martijn Verburg ]
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 861
I'm not sure about p6spy, but you could try to use jamon to monitor your jdbc/sql.

Simply put jamon-2.7.jar in your classpath, and the jamon syntax for driver and url in your xml db configuration file. You can save the jamon html report by writing the html table that is returned by MonitorFactory.getReport() to a file.

I disabled the smileys from your original xml file. Also, you had COM in upper case which seems like the wrong case...



note no space or delimeters occur after DB2E and jamonrealdriver.

for more about it see below.
http://jamonapi.sourceforge.net/#WhatsNew22
[ October 27, 2008: Message edited by: steve souza ]

http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi Sam,

Just so you know, you can UseCodeTags to make you code examples easier to read. I've edited your posts for you in this case

Have you had any further luck with your problem? Let me know if not and I'll try to get it running here as well.


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 861
Code tags don't disable smileys. There is a checkbox in the lower left corner that you have to select.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Originally posted by steve souza:
Code tags don't disable smileys. There is a checkbox in the lower left corner that you have to select.

Yep! The two are unrelated and you should probably use both when posting code examples
Sam Gehouse
Ranch Hand

Joined: Jul 21, 2003
Posts: 281
In the myapp.xml file (that I load from Java main class) in for driverClassName, I changed it to use p6spy, instead of DB2 driver. Snippet of code from myapp.xml is as below:



Also, note that in spy.properties, I have the setting as: useprefix=false

No luck either with the above setting change. I do not get spy.log file getting created anywhere. On the contrary, after changing the driver to p6spy in myapp.xml, I am getting an exception being thrown. Following is the exception stacktrace:

Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [p6spy:com.p6spy.engine.P6SpyDriver]

p6spy.jar is in classpath. Also, spy.properties in classpath. In fact, spy.properties is in the same package as that of the Java main class (driver class that I am running).
[ October 28, 2008: Message edited by: Martijn Verburg ]
Sam Gehouse
Ranch Hand

Joined: Jul 21, 2003
Posts: 281
It is working.
I did not specify the name of the driver correctly - I was missing spy from the package name for P6SpyDriver.

My incorrect value was: com.p6spy.engine.P6SpyDriver
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Well done Sam! And thanks for posting the solution to the forum for others to share.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: P6spy does not create spy.log for stand-alone Java program