Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

closing db connection --> returning to pool. Should be in finally block?

843835Nov 20 2002 — edited Nov 20 2002
hi,
I have read some people say its a bad idea to rely on finally blocks to close/return connections. But isnt it the only true way of assuring that a connection is closed/return.
i.e.,
GetConnection();
//Process a query
CloseConnection();

What if the query gets some type of error and then goes to the catch
i.e.,
catch(Exception e){
//Would need CloseConnection(); here too. Redundant code.
}

Isnt it better to just have a finally block since it is always executed.
catch(Exception e){
//blah blah
}finally{
CloseConnection();
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 18 2002
Added on Nov 20 2002
1 comment
1,289 views