About Question enthuware.ocpjp.v7.2.1158 :

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.1158 :

Post by The_Nick »

Hi,
So basically even with setAutoCommit(false) ,if previously the autoCommit mode has not been changed, it would commit the changes right?

The_Nick.

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

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

Post by admin »

No. As the explanation clearly states, "If the setAutoCommit method is called during a transaction and the auto-commit mode is changed, the transaction is committed. "
So you call setAutoCommit(false) and if the autoCommit mode has not changed i.e. if autoCommit was already false, then it would not cause commit.

HTH,
Paul.

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

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

Post by The_Nick »

admin wrote:No. As the explanation clearly states, "If the setAutoCommit method is called during a transaction and the auto-commit mode is changed, the transaction is committed. "
So you call setAutoCommit(false) and if the autoCommit mode has not changed i.e. if autoCommit was already false, then it would not cause commit.

HTH,
Paul.
Cool, that's what I meant. My bad, it was not clear from what I wrote.
Thanks for replying.

The_Nick.

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

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

Post by admin »

Just read what you wrote again. It was clear enough. Not sure why I interpreted it differently.

pmnserro
Posts: 2
Joined: Tue Oct 13, 2015 11:52 am
Contact:

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

Post by pmnserro »

Hi,
I don't understand why con.close() does not result in the transaction to be commited. As stated in https://docs.oracle.com/javase/tutorial ... tions.html, "When a connection is created, it is in auto-commit mode. This means that each individual SQL statement is treated as a transaction and is automatically committed right after it is executed. (To be more precise, the default is for a SQL statement to be committed when it is completed, not when it is executed. A statement is completed when all of its result sets and update counts have been retrieved. In almost all cases, however, a statement is completed, and therefore committed, right after it is executed.)".
So since in the code it was not called the method con.setAutoCommit(false), there is no reason for autocommit to be disabled. That being said con.close() could replace con.commit() and the transaction would still be commited.

Is my interpretation wrong?

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

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

Post by admin »

The explanation explains this point in detail. It is not known what is included under " //code for enabling transactions". We don't know whether auto commit is true or false. So you need to consider both the possibilities and decide your answer.

pmnserro
Posts: 2
Joined: Tue Oct 13, 2015 11:52 am
Contact:

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

Post by pmnserro »

Thank you for your reply.
In fact what made me interpret the that the answer con.close() is correct was that there is no such thing as enabling transactions, so i thought it that the text was just to deceive. In fact, and for my surprise, it is mentioned in the answer that there is no such thing as enabling transactions. Had the comment been something like "lines of code" "some statement" then it would have been clear that we don't know if the autoCommit was set to false. Just think that it is misleading, no big deal though. Thanks for the support.

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

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

Post by admin »

Yes, it is misleading. That is the goal. You may find such statements in the real exam as well.

HTH,
Paul.

DAlley
Posts: 3
Joined: Sun Oct 19, 2014 3:55 pm
Contact:

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

Post by DAlley »

My difficulty came in what the test was asking:
What statement can replace the call to con.commit()?
It does not say "and achieve the same result". So my thinking was, well you are either going to commit or rollback.

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

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

Post by admin »

it does say,"...and still have the transaction committed?"

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests