I am using PreparedStatement
to build my query but i want to print the final statement after replacing all the variables (replacing the '?') before executing it, apparently the method i need is PreparedStatement#toString()
like this for example
PreparedStatement query = connection.prepareStatement(select ? from ?);
System.out.println("Before : " + query.toString());
query.setString(1, column);
query.setString(2, table);
System.out.println("After : " + query.toString());
and the output should be something like this :
Before : com.mysql.jdbc.JDBC4PreparedStatement@fa9cf: SELECT ** NOT SPECIFIED ** FROM ** NOT SPECIFIED **
After : com.mysql.jdbc.JDBC4PreparedStatement@fa9cf: SELECT column FROM table
but what i get is
Before : com.mysql.jdbc.JDBC4PreparedStatement@fa9cf
After : com.mysql.jdbc.JDBC4PreparedStatement@fa9cf
i don't know what is wrong