By using prepared statements, you can't retrieve the query :
- You have a statement, containing placeholders
- it is sent to the DB server
- and prepared there
- which means the SQL statement is "analyzed", parsed, some data-structure representing it is prepared in the memory
- And, then, you have bound variables
- which are sent to the server
- and the prepared statement is executed -- working on those data
But there is no reconstruction of an actual real SQL query -- neither on the Java-side, nor on the database side. So, there is no way to get the prepared statement's SQL -- as there is no such query. And, if you are using it for debugging purpose you can try following:
- Output the code of the statement, with the placeholders and the list of data
- Or "build" some SQL query "by hand