aspose file tools*
The moose likes JDBC and the fly likes How to see agenerated PreparedStatement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to see agenerated PreparedStatement" Watch "How to see agenerated PreparedStatement" New topic
Author

How to see agenerated PreparedStatement

L Duperval
Ranch Hand

Joined: May 14, 2003
Posts: 63
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


Live Free, Live Happy
L Duperval
Ranch Hand

Joined: May 14, 2003
Posts: 63
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

Joined: Mar 06, 2001
Posts: 13459

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.
 
 
subject: How to see agenerated PreparedStatement