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 passin
You can have a look at p6spy , it's a proxy to your database driver that allows monitoring and logging.
Most logging framework have the notion for Nested Diagnostic Context. You could save your query and its parameters there when you fill up the prepared statement.
Or, perhaps, do it in one step:
PreparedStatement fillAndLog(Connection conn, String query, Object... args) {
int i = 0;
PreparedStatement pstmt = conn.prepareStatement(query);
for (Object o : args) {
if (o instanceof String) {
pstmt.setString(i, (String)o);
} // else...
i++;
}
log.debug(String.format(query.replaceAll("\\?", "%s"), args));
return pstmt;
}