Discovering SQL from a ResultSet

3

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

?

    
asked by anonymous 21.07.2015 / 22:11

3 answers

2

You should get the SQL from java.sql.PreparedStatement:

System.out.println(ps);

Just call the PrepareStatement toString.

    
21.07.2015 / 22:17
2

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.

    
24.07.2015 / 17:32
0

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.

    
25.07.2015 / 16:33