What statements are correct about JDBC transactions (2 answers)?

  1. [_] [a] A transaction is a set of successfully executed statements in the database

  2. [_] [b] A transaction is finished when commit() or rollback() is called on the Connection object,

  3. [_] [c] A transaction is finished when commit() or rollback() is called on the Transaction object

  4. [_] [d] A transaction is finished when close() is called on the Connection object.


Correct Option: B,D

AI Explanation

To answer this question, we need to understand the concept of JDBC transactions. Let's go through each statement to determine which ones are correct:

A. [ ] A transaction is a set of successfully executed statements in the database - This statement is incorrect. A transaction is a logical unit of work that can consist of one or more database operations, but it is not necessarily limited to successfully executed statements. Transactions can also include statements that may fail or be rolled back.

B. [ ] A transaction is finished when commit() or rollback() is called on the Connection object - This statement is correct. In JDBC, a transaction is considered finished when either the commit() or rollback() method is called on the Connection object. The commit() method is used to permanently save the changes made in the transaction, while the rollback() method is used to discard the changes and revert the database to its previous state.

C. [ ] A transaction is finished when commit() or rollback() is called on the Transaction object - This statement is incorrect. In JDBC, there is no Transaction object. Transactions are managed using the Connection object, and the commit() or rollback() methods are called directly on the Connection object.

D. [ ] A transaction is finished when close() is called on the Connection object - This statement is correct. When the close() method is called on the Connection object, any pending transaction is automatically committed. Therefore, closing the Connection object can also be considered as finishing the transaction.

Based on the explanations above, the correct statements about JDBC transactions are B and D.

Find more quizzes: