• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Closing connections properly...

 
JP Estrada
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys

Is it ok to just set a connection object to null? like conn=null,
instead of using conn.close() ? An application was turned over to me and it's having null pointer exceptions with it's connection objects. The error is very intermittent though, so i thought the number connections is getting over the limit of the maximum number of connections set...
 
Paul Clapham
Sheriff
Posts: 21588
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do have to close a connection when you are finished using it. Doing that in the "finally" part of a try-catch-finally block is the most reliable way of making sure it happens.

As for assigning null to variables, that's almost always pointless. The only place you really have to do that is when the variable refers to a very large object, and you don't need the object any more, and you want to make it available for garbage collection. A JDBC Collection is not a large object.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic