About Question enthuware.ocpjp.v7.2.1155 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

About Question enthuware.ocpjp.v7.2.1155 :

Post 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.

The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

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

Post 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.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

tanzwud
Posts: 19
Joined: Mon Sep 01, 2014 9:45 pm
Contact:

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

Post 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.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Yes, you should rely on what the JavaDoc says because implementations may not always be compliant.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests