aspose file tools*
The moose likes JDBC and the fly likes Display a PreparedStatement content Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Display a PreparedStatement content" Watch "Display a PreparedStatement content" New topic
Author

Display a PreparedStatement content

Celinio Fernandes
Ranch Hand

Joined: Jun 28, 2003
Posts: 547

Hello,
I am using JDBC driver
I would like to know if there is a way to display the SQL query associated
with a
PreparedStatement.
I would like to fill the parameters, and then display the query as it will
be thrown
to the Websphere server to debug my application.
Sample: PreparedStatement ps
= new connection.prepareStatement("Select * from foo where bar = ?") ;
ps.setInt(1, 1) ;
and then use somethind like:
// This line does not actually work. System.out.println("Query is: "
+ps.toString()) ;
// But i would like it to print Query is: Select * from foo where bar = 1
Thanks


SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCBCD 5
Visit my blog
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Check out the DebuggableStatement. There is a thread about it here
But first...
"longbeach forever",
Display names are not allowed to be fictitious. Please see the JavaRanch naming policy here then edit your profile to set a valid display name.
Accounts with invalid display names get deleted.
thanks,
Dave.
Celinio Fernandes
Ranch Hand

Joined: Jun 28, 2003
Posts: 547

thanks, and i updated my profile
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You just updated it to another invalid display name. You need to look at the JavaRanch naming policy.
Your display name must be two words: your first name, a space, then your last name. Fictitious names are not allowed.
Please try again. It's unfortunate when get deleted through misunderstandings!
thanks,
Dave
Celinio Fernandes
Ranch Hand

Joined: Jun 28, 2003
Posts: 547

the DebuggableStatement class seems to be working, i tried it.
But you need to import at least 8 classes ...
isn't there a quicker way ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Display a PreparedStatement content