Which three are true?

Which three are true?

Which three are true?

A.
A setAutoCommit (False) method invocation starts a transaction context.

B.
An instance of Savepoint represents a point in the current transaction context.

C.
A rollback () method invocation rolls a transaction back to the last savepoint.

D.
A rollback () method invocation releases any database locks currently held by this connection
object.

E.
After calling rollback (mysavepoint), you must close the savepoint object by calling
mySavepoint.close() .

Explanation:

A:The way to allow two or more statements to be grouped into a transaction is to disable the autocommitmode. After the auto-commit mode is disabled, no SQL statements are committed until you
call the methodcommit explicitly. All statements executed after the previous call to the method
commit are included in thecurrent transaction and committed together as a unit.
Note:When a connection is created, it is in auto-commit mode. This means that each individual
SQL statementis treated as a transaction and is automatically committed right after it is executed.
(To be more precise, thedefault is for a SQL statement to be committed when it is completed, not
when it is executed. A statement iscompleted when all of its result sets and update counts have
been retrieved. In almost all cases, however, astatement is completed, and therefore committed,
right after it is executed.)

B:The method Connection.setSavepoint, sets a Savepoint object within the current transaction.
The
Connection.rollback method is overloaded to take a Savepoint argument. When a transaction is
rolled back toa savepoint all changes made after that savepoint are undone.
C: calling the method rollback terminates a transaction and returns any values that were modified
to theirprevious values. If you are trying to execute one or more statements in a transaction and
get a SQLException, call the method rollback to end the transaction and start the transaction all
over again.



Leave a Reply 6

Your email address will not be published. Required fields are marked *


BKhateib

BKhateib

RollBack
Undoes all changes made in the current transaction and releases any database locks currently held by this Connection object. This method should be used only when auto-commit mode has been disabled.
source Java 7 documentation so D is true, C is totally wrong

l0c

l0c

C is indeed wrong, it doesn’t rollback to the latest Savepoint, it rolls back to the start (as if nothing happened).

C would be right if it would mention passing the Savepoint object as a parameter.