• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Printing prepared statement to console

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at this one
[ March 26, 2007: Message edited by: suresh charan ]
reply
    Bookmark Topic Watch Topic
  • New Topic