views:

33

answers:

3

Hi,

I am trying to print out the SQL statement that my EJB uses to create record in the database into a log file.

Does anyone have any experience to do this.

thank you.

Cheers,

A: 

Sure, use log4j to write to the console log.

duffymo
Mmm it's a bit tricky the code uses EJB Entity to insert record to database e.g: someentity.create(id). The challenging part is to print out the SQL that the EJB entity execute when we call the create ()
zfranciscus
Why do you think you need the SQL?
duffymo
+2  A: 

Check the documentation/FAQ for your driver. For example, if you're using Oracle's driver, these may help:

Oracle JDBC Trace Facility
java.util.logging

If you're using the WebLogic driver:

Tracking JDBC Calls with WebLogic JDBC Spy

kschneid
I manage to found some documentation on how to turn on JDBC trace messages.http://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq.html#32_00
zfranciscus
A: 

p6spy is a nice utility for this.

See http://www.p6spy.com/

P6Spy is an open source framework for applications that intercept and optionally modify database statements. The P6Spy distribution includes the following modules: P6Log. P6Log intercepts and logs the database statements of any application that uses JDBC. This application is particularly useful for developers to monitor the SQL statements produced by EJB servers, enabling the developer to write code that achieves maximum efficiency on the server. P6Spy is designed to be installed in minutes and requires no code changes.

pushNpop