Reusing of a PreparedStatement between methods?

Posted by MRalwasser on Stack Overflow See other posts from Stack Overflow or by MRalwasser
Published on 2011-01-10T13:49:32Z Indexed on 2011/01/10 13:53 UTC
Read the original article Hit count: 176

We all know that we should rather reuse a JDBC PreparedStatement than creating a new instance within a loop.

But how to deal with PreparedStatement reuse between different method invocations? Does the reuse-"rule" still count?

Should I really consider using a field for the PreparedStatement or should I close and re-create the prepared statement in every invocation? (Of course an instance of such a class would be bound to a Connection which might be a disadvantage)

I am aware that the ideal answer might be "it depends".
But I am looking for a best practice for less experienced developers that they will do the right choice in most of the cases.

© Stack Overflow or respective owner

Related posts about java

Related posts about Performance