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 auto-commit mode.After the auto-commit mode is disabled, no SQL statements are committed until you call the method commit explicitly. All statements executed after the previous call to the method commit are included in the current 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 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.)
B:The method Connection.setSavepoint, sets a Savepoint object within the current transaction. The Connection.rollback method is overloaded to take a Savepoint argument.
C:calling the method rollback terminates a transaction and returns any values that were modified to their previous 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.
Corrects asnwers are A, B, D
C is incorrect as a rollback() without passing a svepoint rolls all the transaction back!
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.
A, B, D
setAutoCommit(boolean autoCommit)
throws SQLException
Sets this connection’s auto-commit mode to the given state. If a connection is in auto-commit mode, then all its SQL statements will be executed and committed as individual transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either the method commit or the method rollback. By default, new connections are in auto-commit mode.
The commit occurs when the statement completes. The time when the statement completes depends on the type of SQL Statement:
For DML statements, such as Insert, Update or Delete, and DDL statements, the statement is complete as soon as it has finished executing.
For Select statements, the statement is complete when the associated result set is closed.
For CallableStatement objects or for statements that return multiple results, the statement is complete when all of the associated result sets have been closed, and all update counts and output parameters have been retrieved.
NOTE: If this method is called during a transaction and the auto-commit mode is changed, the transaction is committed. If setAutoCommit is called and the auto-commit mode is not changed, the call is a no-op.
Savepoint
The representation of a savepoint, which is a point within the current transaction that can be referenced from the Connection.rollback method. When a transaction is rolled back to a savepoint all changes made after that savepoint are undone.
rollback(Savepoint savepoint)
Undoes all changes made after the given Savepoint object was set.
rollback()
Undoes all changes made in the current transaction and releases any database locks currently held by this Connection object.
+1
ans== is A,B,D
A B D
A B and D
abd