• 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

ResultSet.close()

 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Result rs = ....;
...
..
rs.close();


For "rs.close()",

1. if we know rs is not null, is it possible that "rs" still can not be closed due to some SQLException ?

2. if ResultSet can not be closed for some reason, can we still close a Statement ?
 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1. if we know rs is not null, is it possible that "rs" still can not be closed due to some SQLException ?



Yes.

if ResultSet can not be closed for some reason, can we still close a Statement ?


Assuming you mean a SQLException... yes you should still attempt to close the statement (and underlying connection). The exception could be a connection loss but it could mean many other things as well that do not relate to your closing the Statement.
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ben oliver:
Result rs = ....;
...
..
rs.close();


For "rs.close()",

1. if we know rs is not null, is it possible that "rs" still can not be closed due to some SQLException ?

2. if ResultSet can not be closed for some reason, can we still close a Statement ?



1. yes, certainly. Easy example: the database has crashed...
2. sometimes yes, sometimes no. With good networks and a good database and a Java program running on a machine that's not overloaded, it will be incredibly incredibly rare to have a rs.close() error and have its related Statement.close() succeed, so much so that many good programmers will do them all in one try/catch. However, it a situation with intermittent network or OS problems it becomes more likely, and many good programmers will therefore put each of them in their own try/catch blocks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic