Page 1 of 1

Closing a connection question

Posted: Sat Jan 23, 2016 12:55 pm
by krohani
Okay from the questions and answer explanations (see below) I understand that closing a Connection renders the resultset and statment not usable however if that is the case then why is it that the "proper" way taught to close out everything is to explicitly in a try/catch close connection, resultset and statement? Why not just close the connection in a try catch?

If closing a connection takes care of the other two why are we being taught to close all three? Very curious.

From answer explanation:
In this case, although we are not closing the ResultSet directly, we are closing the Statement object from which the ResultSet was retrieved and when a Statement object is closed, its current ResultSet object, if one exists, is also closed.

Re: Closing a connection question

Posted: Sat Jan 23, 2016 9:49 pm
by admin
In most applications a connection is never closed explicitly because it is retrieved from a connection pool. (The pool manages the opening and closing of a connection). That is why it is a good idea to close the result sets and statements. Otherwise, there is no need.
HTH,
Paul.

Re: Closing a connection question

Posted: Wed Jan 27, 2016 12:16 pm
by krohani
admin wrote:In most applications a connection is never closed explicitly because it is retrieved from a connection pool. (The pool manages the opening and closing of a connection). That is why it is a good idea to close the result sets and statements. Otherwise, there is no need.
HTH,
Paul.

Ah yes that is true and makes sense. Thank you sir!

Kirk