Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt while closing connection.

 
Balakrishnan sanjay
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you close connection, the statement and resultset both, attached with that particular connection will get closed automatically.
 
Dennis Zandvliet
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In standalone program, it does'it throw any application. but in an application ???
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic