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?
Asked
Active
Viewed 195 times
1

Leigh
- 28,765
- 10
- 55
- 103

user1439696
- 13
- 5
-
Possible dupe of http://stackoverflow.com/questions/2683214/get-query-from-java-sql-preparedstatement – matt freake Jun 18 '12 at 08:09
1 Answers
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