1

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

Community
  • 1
  • 1
hbelmiro
  • 987
  • 11
  • 31

1 Answers1

2

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

In case it doesn't work, refer here.

Community
  • 1
  • 1
teobais
  • 2,820
  • 1
  • 24
  • 36