File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Printing prepared statement to console Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Printing prepared statement to console" Watch "Printing prepared statement to console" New topic
Author

Printing prepared statement to console

Prasad Tamirisa
Ranch Hand

Joined: Mar 26, 2007
Posts: 130
Hi all,

Is there any way that i can print (i mean a debug statement) a prepared statement to the console.

i tried using

prpstmt.toSting();

but it doesn't seem to be working....

can any one suggest in this aspect.


Regards,
Durga Prasad
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
There is not direct way to get the SQL being executed by the preparedstatement from the java side (unless you use JDBC driver wrappers like p6spy). You need to write some sort of reflection code to get the SQL. Here is what I did

1. Used debug to break on preparedstatement execute statement from IDE. Examined the preparedstatement object and figured out the sql is stored in which field.

2. Execute below code



This worked fine with Oracle JDBC driver. The fields may vary based on the DB & Driver.
suresh charan
Greenhorn

Joined: Jun 15, 2006
Posts: 8
Look at this one
[ March 26, 2007: Message edited by: suresh charan ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Printing prepared statement to console
 
Similar Threads
inserting text with single and doubl quotes
Hibernate Prepared Statements in XML files?
Urgent Java interview question 6+ yrs exp.
Inserting | into oracle DB
Interview question