2

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

0

1 Answer 1

2

Just print it with the standard way System.out.println(preparedStatement); .

In case it doesn't work, refer here.

Sign up to request clarification or add additional context in comments.

1 Comment

I don't have the PreparedStatement. That's what I'm asking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.