• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt while closing connection.

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you close connection, the statement and resultset both, attached with that particular connection will get closed automatically.
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In standalone program, it does'it throw any application. but in an application ???
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic