*
The moose likes JDBC and the fly likes Doubt while closing connection. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Doubt while closing connection." Watch "Doubt while closing connection." New topic
Author

Doubt while closing connection.

Balakrishnan sanjay
Greenhorn

Joined: Jul 15, 2009
Posts: 3
Hi ,
I am confusing in the below scenoria.

try{
Connection -
Statment -
ResultSet
}catch(){
}finally{

//should be
resultset.close();
statement.close();
connection.close();
}
Instead of that if i close the connection first in the finally blocks what will happen... Is the statment and resultset object take handle by JVM?

Thanks in advance.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
When you close connection, the statement and resultset both, attached with that particular connection will get closed automatically.
Dennis Zandvliet
Ranch Hand

Joined: Jun 19, 2008
Posts: 60
Adeel Ansari wrote:When you close connection, the statement and resultset both, attached with that particular connection will get closed automatically.


Is this always the case? Because according to this and other articles this is not always the case?
Balakrishnan sanjay
Greenhorn

Joined: Jul 15, 2009
Posts: 3
In standalone program, it does'it throw any application. but in an application ???
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30136
    
150

Adeel Ansari wrote:When you close connection, the statement and resultset both, attached with that particular connection will get closed automatically.

In a properly implemented driver. Which unfortunately one cannot rely on having.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Jeanne Boyarsky wrote:
Adeel Ansari wrote:When you close connection, the statement and resultset both, attached with that particular connection will get closed automatically.

In a properly implemented driver. Which unfortunately one cannot rely on having.


Yes.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
I believe, there are very few, if there are, applications which don't use pooling for connections. So, in case you are employing a pooling mechanism, then there is no closing for connections on your end, therefore you must close statements and resultsets. Of course you need to set the connection back to the pool.

I believe, closing a statement should automatically close the resultset. I hope there are no exceptions in this regards. Please let me know. Further, you must free all Blob, Clob etc. objects, because they remain valid, even when you close the resultset.

Cheers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt while closing connection.
 
Similar Threads
ORA-01000 maximum open cursors exceeded
Connection Problem
Result set not showing the latest data
Closing ResultSet and Statement
Dbtags+closeConnection