1

I created a PreparedStatementWrapper object containing an INSERT statement. Now I would like to print my object. I want to test my INSERT statement, to see that it is correct. How can I do that?

Leigh
  • 28,765
  • 10
  • 55
  • 103

1 Answers1

0

Just use System.out.println() and toString() method before you execute it.

PreparedStatement ps = con.prepareStatement(QUERY);
ps.setString(1, "Test");
System.out.println(ps.toString());

EDIT: It works only if you are using MYSQL driver.

Simon Dorociak
  • 33,374
  • 10
  • 68
  • 106
  • yes, you right it works only with MySQL driver. So it's not defined in JDBC. – Simon Dorociak Jun 18 '12 at 08:44
  • Works for PostgreSQL as well. Wether or not it works depends on how the JDBC driver's implementation of the Statement interface implements the `toString()` method. –  Jun 18 '12 at 13:11