Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When do you close PreparedStatements?

 
Adam Altmann
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We're having a minor debate here, and we've been unable to find a definitive answer with Google.

When should you close PreparedStatements, and why?

Particularly, should you close them before reassigning?

For example:

PreparedStatement pstmt = null;

pstmt = whatever;
//Should I close it here? How come?
pstmt = somethingElse;



Thanks in advance.
 
Paul Clapham
Sheriff
Posts: 21581
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should close it when you're finished using it. That would be before you assign null to the only variable referring to it, not after that, of course. Why? So the database knows you're finished using it and can clean up whatever resources it was using to support it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic