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

How to see agenerated PreparedStatement

 
L Duperval
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic