I have a thread which iterates a pool of occupied connections and verifies if each Connection has reached the maximum time allowed for being at this pool.
If the Connection reaches that time, I perform a rollback, close the Connection and log a message containing information about the Connection.
I would like to add the SQL command performed by that Connection to the logged message.
Is there a way of getting the SQL, or the PreparedStatement, from a java.sql.Connection?
I've wondered to extend java.sql.Connection and inject that information to the object before execute the command. So that, I would be able to get it when necessary.
Do you know a more elegant way of doing that?
EDIT
It isn't duplicate. This question is about PreparedStatement and I don't have it. I only have a java.sql.Connection