I want to implement logging of all executed statements with actual bind parameters when using Oracle JDBC. And I would prefer that I could create such logging method only passing PreparedStatement object as parameter.
For example I have created PreparedStatement and have bound one parameter
PreparedStatement ps = conn.prepareStatement(
"SELECT * FROM employees WHERE employee_id = ?");
ps.setInt(1,1);
Now I would like to be able to get from ps the actual SQL statement "SELECT * FROM employees WHERE employe_id = 1" that I could put in log file.
So far I found that I can use
((oracle.jdbc.driver.OracleStatement) ps).getOriginalSql()
to get
SELECT * FROM employees WHERE employe_id = ?
Now I need some way to get the list of current bind variables from ps so that I could replace ? with bind parameter values.
I tried to look in ps.getClass().getDeclaredFields() and ps.getClass().getSuperclass().getDeclaredFields() but so far couldn't find the place where bind parameter values and their types are stored.
Any suggestions where to look for them?