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 :-)