About Question enthuware.ocpjp.v7.2.1158 :
Moderator: admin
-
- Posts: 132
- Joined: Thu May 16, 2013 9:23 am
- Contact:
About Question enthuware.ocpjp.v7.2.1158 :
Hi,
So basically even with setAutoCommit(false) ,if previously the autoCommit mode has not been changed, it would commit the changes right?
The_Nick.
So basically even with setAutoCommit(false) ,if previously the autoCommit mode has not been changed, it would commit the changes right?
The_Nick.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1158 :
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.
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.
-
- Posts: 132
- Joined: Thu May 16, 2013 9:23 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1158 :
Cool, that's what I meant. My bad, it was not clear from what I wrote.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.
Thanks for replying.
The_Nick.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1158 :
Just read what you wrote again. It was clear enough. Not sure why I interpreted it differently.
-
- Posts: 2
- Joined: Tue Oct 13, 2015 11:52 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1158 :
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?
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?
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1158 :
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.
-
- Posts: 2
- Joined: Tue Oct 13, 2015 11:52 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1158 :
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.
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.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1158 :
Yes, it is misleading. That is the goal. You may find such statements in the real exam as well.
HTH,
Paul.
HTH,
Paul.
-
- Posts: 3
- Joined: Sun Oct 19, 2014 3:55 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1158 :
My difficulty came in what the test was asking:
It does not say "and achieve the same result". So my thinking was, well you are either going to commit or rollback.What statement can replace the call to con.commit()?
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1158 :
it does say,"...and still have the transaction committed?"
Who is online
Users browsing this forum: No registered users and 3 guests