Page 1 of 1
About Question enthuware.ocpjp.v7.2.1158 :
Posted: Sat Sep 14, 2013 8:36 am
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.
Re: About Question enthuware.ocpjp.v7.2.1158 :
Posted: Sat Sep 14, 2013 8:53 am
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.
Re: About Question enthuware.ocpjp.v7.2.1158 :
Posted: Sat Sep 14, 2013 10:05 am
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.
Re: About Question enthuware.ocpjp.v7.2.1158 :
Posted: Sat Sep 14, 2013 10:24 am
by admin
Just read what you wrote again. It was clear enough. Not sure why I interpreted it differently.
Re: About Question enthuware.ocpjp.v7.2.1158 :
Posted: Tue Oct 13, 2015 12:01 pm
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?
Re: About Question enthuware.ocpjp.v7.2.1158 :
Posted: Tue Oct 13, 2015 9:24 pm
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.
Re: About Question enthuware.ocpjp.v7.2.1158 :
Posted: Wed Oct 14, 2015 4:02 pm
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.
Re: About Question enthuware.ocpjp.v7.2.1158 :
Posted: Wed Oct 14, 2015 9:38 pm
by admin
Yes, it is misleading. That is the goal. You may find such statements in the real exam as well.
HTH,
Paul.
Re: About Question enthuware.ocpjp.v7.2.1158 :
Posted: Thu Dec 17, 2015 12:19 pm
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.
Re: About Question enthuware.ocpjp.v7.2.1158 :
Posted: Mon Dec 21, 2015 3:25 am
by admin
it does say,"...and still have the transaction committed?"