• 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

How to see agenerated PreparedStatement

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,
Is there any way for me to create a PreparedStatement and then see what is generated? I have a query I'm building but it doesn't give me the results I expect and I have a suspicion it's because the generated SQL isn't what I want. But nowhere in the Statement or PreparedStatement is there a getQuery() that returns the SQL string for the query, for inspection.
Is there a way to get this?
Thanks,
L
 
L Duperval
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figure I might as well add a little more info on what I'm trying to do. I've got a table with a CREATION_DATE column. I want to get data that was created in the last n minutes. So I've set up something like this:
import java.sql.Date;
.
.
.
int getCount(int minutes) {
int delay = minutes * 60000;
// set up connection here
Connection conn;
.
.
.
ResultSet rs = null;
Date fromDate = new Date(System.currentTimeMillis() - delay);
String sqlQuery = "select count(*) from TRX where (state = 999) " +
"and creation_date > ?";
ps = conn.prepareStatement(sqlQuery);
ps.setDate(1, fromDate);
rs = ps.executeQuery();
if (rs.next()) {
nbPendingTrx = rs.getInt(1);
}
.
.
.

My problem is that it looks like the time is not used in the query. I've the impression that only the date is used. But without seeing the generated query, I can't know for sure.
Thanks,
L
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a few ways to achieve this, but I find one of the easiest is to implement the DebuggableStatement. Here's everything you need at JavaWorld.
Dave.
 
Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic