Page 1 of 1

About Question enthuware.ocpjp.v7.2.1155 :

Posted: Fri Sep 20, 2013 3:32 am
by The_Nick
Hi,
It would be the same thing closing a Connection right? Closing a connection closes implicitly all the statements and resultset to it connected right?
Thanks in advance.

Re: About Question enthuware.ocpjp.v7.2.1155 :

Posted: Fri Sep 20, 2013 3:40 am
by The_Nick
UPDATE: my concern is about the answer of this thread of Marko Topolonik at the bottom page:

http://stackoverflow.com/questions/1402 ... -resultset
The details are ultimately down to each JDBC driver implementation; however, once a connection to the database is closed, everything related to it is disposed at the DB side, so there is nothing much the client side can do but auto-close the objects representing these resources.

You never know in what ways the databeses/drivers could be broken (there may be resource leaks, for example), therefore the best practice recommendation is to close everything explicitly.
share|improve this answer

answered Dec 24 '12 at 17:55
Marko Topolnik
resource leaks? So actually closing the connection does not guarantee anything right?
Thanks in advance.

The_Nick.

Re: About Question enthuware.ocpjp.v7.2.1155 :

Posted: Fri Sep 20, 2013 6:03 am
by admin
Well, closing the connection closes database connection. That is guaranteed. Since Statement and ResultSet are tied to a connection, they will be useless after the connection is closed.
I am not sure what resource leaks the poster is talking about. But anything that is not in the Java world cannot be guaranteed by the JVM. After all, the database is a third party application, beyond the control of JVM. You can potentially write a database with resource leaks and JVM can't do anything about it.

HTH,
Paul.

Re: About Question enthuware.ocpjp.v7.2.1155 :

Posted: Thu Nov 13, 2014 11:27 am
by tanzwud
Have problem with this question. I had a nasty surprise with the outcome. The database were I test all the code HSQLDB and closing statement at line 11 not throwing any Exceptions, even If I close the connection on the same line. Not shure about any other databases. But seems like the close method is DB related or in case I have same question on the exam am I need to pick the option with exception since JavaDoc says so? Many thanks.

Re: About Question enthuware.ocpjp.v7.2.1155 :

Posted: Fri Nov 14, 2014 1:12 am
by admin
Yes, you should rely on what the JavaDoc says because implementations may not always be compliant.