Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to fetch the sql query from the prepared statement at runtime?

 
Deepak Kumar
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Below there is an snippet of code ,
Assume con,ps,rs are defined properly.



Thanks & Regards,
Deepak Kumar G.S
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no out of the box solution for you, but this website: Save time debugging your database queries with DebuggableStatement has a solution: A DebuggableStatement .

It can print your sql statement, with bind parameters inlined into the query.
 
Scott Selikoff
author
Saloon Keeper
Posts: 4014
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just use a debugging version of the driver. Many JDBC vendors provide a regular and debug version, with the debug version outputting the SQL statements. Also, its possible your current driver will output the SQL if you add some config parameters to the driver connection string. I don't recommend swapping the DebuggableStatement method for 2 reasons- you have to refactor (then later unfactor) your code to use it, and there's all ready a solution available by most, if not all, JDBC drivers. I take issue with JavaWorld post in that it invents a solution to a problem that all ready has a better solution available, one that doesn't require you to change your code.

If all else falls you can turn on tracing on the database server and monitor the queries on that end.
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have also considered advising the debugging driver, but that does not output the sql statement with the bind parameters embedded, does it? That was what the OP was asking.
If the debugging driver does that, than I am willing to revoke my advise .
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah. I see it supports in-lining bind parameters by using property replace.bindParams.
I hereby revoke my proposal.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic