I used PreparedStatement in my Java program. I need to debug the SQL query because it’s not working fine.
Is there is away to print the used SQL statement with the values inserted
for example in PreparedStatement:
select * from table where a=?
and than I set the ?
could I print the used SQL, for example:
select * from table where a=1
It can’t be done with
java.sql.PreparedStatementinterface itself; it depends on the implementation by your database vendor.But you’re in luck; the MySQL driver allows you to do it using its
toStringimplementation:http://www.avajava.com/tutorials/lessons/how-do-i-display-a-prepared-statement-with-bind-variables-using-mysql.html
You need to be aware that using this vendor-specific feature binds your code to MySQL. You can’t change databases without changing your code.