File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Closing connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Closing connection" Watch "Closing connection" New topic

Closing connection

PN Kumar
Ranch Hand

Joined: Sep 08, 2001
Posts: 38
When closing the connection with the back-end server, wont the result set and statement object be closed automatically? Or is explicit closing of statement and resultSet a preferred way of doing it?
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
Explicit closing of the ResultSet and Statement is the preferred way to go. This let's the database server free its resources.
If you close the Connection w/out closing the ResultSet, your Java resources are freed, but the database may still consider the ResultSet (cursor) to be open. I've seen this lead to a "Maximum number of cursors exceeded" error.
I agree. Here's the link:
subject: Closing connection