When we create a PreparedStatement we use '?' chars to then be replaced by setted parameters.
How can we see the final SQL string after these parameters are set?
There is no final SQL string, the version with placeholders is what is actually sent to server. The data is sent completely separately from it as you execute queries on the prepared statement.
You can log the string with placeholders, and then each dataset individually.
Your code could combine them in the log to an actual SQL string if that's what you want:
String query = "SELECT a FROM b WHERE c = ?";
...
pstmt.setString(1, "asd");
logSQL( query, "asd");
logSQL
would then actually log "SELECT a FROM b WHERE c = 'asd'"
. Could be that someone has actually implemented this before...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With