Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Databases > Re: how to get ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 3631 of 3876
Post > Topic >>

Re: how to get the query from the Statement object

by RedGrittyBrick <RedGrittyBrick@[EMAIL PROTECTED] > Jan 15, 2008 at 09:55 PM

Steve wrote:
> Is there a way to get the query from the Statement object? I couldn't
> find the API on that purpose.
> 

Generally if it's not in the API docs then there isn't.

Presumably you mean Interface java.sql.Statement and the String passed 
to it's executeQuery method.

Perhaps you could write your own class that implements Statement, 
encapsulates the Statement obtained by Connection.createStatement and 
which keeps track of the most recent query?

   Connection connection = DriverManager.getConnection( ... );
   Statement statement = connection.createStatement();
   MyStatement myStatement = new MyStatement(statement);
   String sql = "select count(*) from aristocrat";
   ResultSet rs = myStatement.executeQuery(sql);
   ...
   String lastUsedQuery = myStatement.getLastQuery();
   if (lastUsedQuery.equals(sql))
     System.out.println("I'm astonished!");

This makes no sense to me, if it doesn't to you either, I suggest you 
explain a bit about the background :-)
 




 2 Posts in Topic:
Re: how to get the query from the Statement object
RedGrittyBrick <RedGri  2008-01-15 21:55:45 
Re: how to get the query from the Statement object
Lew <lew@[EMAIL PROTEC  2008-01-15 19:30:35 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Dec 3 23:35:51 CST 2008.