| Author |
Closing connections properly...
|
JP Estrada
Ranch Hand
Joined: Mar 21, 2006
Posts: 47
|
|
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
Bartender
Joined: Oct 14, 2005
Posts: 16487
|
|
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.
|
 |
 |
|
|
subject: Closing connections properly...
|
|
|