Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

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

 
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
 
Bartender
Posts: 2658
19
Netbeans IDE C++ Linux
  • 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.
 
author
Posts: 4173
29
jQuery Eclipse IDE Java
  • 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: 2658
19
Netbeans IDE C++ Linux
  • 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: 2658
19
Netbeans IDE C++ Linux
  • 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.
 
Heroic work plunger man. Please allow me to introduce you to this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic