File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Closing connections properly... Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Closing connections properly..." Watch "Closing connections properly..." New topic
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
    
    2

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Closing connections properly...
 
Similar Threads
org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool exhausted
Detailed info on pooled JDBC connections?
getting "max open cursors exceeded" from EJB
Multiple DataSources
what is connection pooling?