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 (keep it local)?
(Of course an instance of such a class would be bound to a Connection
which might be a disadvantage in some architectures)
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.