Mohammed Housseyn Taleb Mohammed Housseyn Taleb - 20 days ago 5
Java Question

Is there any way to retrieve the executed query from java ResultSet?

I created a method called

public static ResultSet ExecuteSQLQuery(String myQuery)
now at run-time I need to retrieve the executed query from the ResultSet.

I wonder if it is possible to retrieve the executed query from the ResultSet ?

Answer

In short: No.

It might be possible to use getStatement from the ResultSet. Some JDBC drivers may expose the query in the statement's toString method, but even if this is the case it should not be relied upon.

You'll have to save the query and keep it around if you want to use it later.