I have a java ResultSet object that does not know the SQL / Parameters that generated it. I would like to know how do I get the SQL used to create it? would have something like:
rs.getStm.getSql
?
I have a java ResultSet object that does not know the SQL / Parameters that generated it. I would like to know how do I get the SQL used to create it? would have something like:
rs.getStm.getSql
?
You should get the SQL from java.sql.PreparedStatement:
System.out.println(ps);
Just call the PrepareStatement toString.
I'm writing this by relying on this javadoc .
By javadoc, class FirebirdResultSet
inherits from ResultSet
of library java.sql
.
The class ResultSet
has method getStatement()
that returns an object Statement
; then you can follow the user's response @Afonso , and call the toString
method of the Statement
class.
Only complementing Mr. Afonso. With Postgre it works too. Only use the toString () method with the PreparedStatement.
preparedStatement = conection.prepareStatement("SELECT * FROM usuario");
System.out.println(preparedStatement.toString());
Console:
SELECT * FROM usuario
With Common Statement does not work because sql is inserted directly with the executeQuery method.