1.

Explain the methods available for Transaction Management in JDBC.

Answer»

The connection interface is having 5 methods for transaction management. They are given below:

  • setAutoCommit() method:
    The value of AutoCommit is set to TR
    UE by default. After the SQL statement execution, it will be committed automatically. By using this method we can set the value for AutoCommit.
    Syntax: conn.setAutoCommit(boolean_value)
    Here, boolean_value is set to TRUE for enabling autocommit mode for the connection, FALSE for disabling it.
  • Commit() method:
    The commit() method is USED for committing the data. After the SQL statement execution, we can call the commit() method. It will commit the CHANGES made by the SQL statement.
    Syntax: conn.commit();
  • Rollback() method:
    The rollback() method is used to undo the changes made till the LAST commit has occurred. If we face any problem or exception in the SQL statements execution flow, we may roll back the transaction.
    Syntax: conn.rollback();
  • setSavepoint() method:
    If you have set a savepoint in the transaction (a group of SQL statements), you can use the rollback() method to undo all the changes till the savepoint or after the savepoint(), if something goes WRONG within the current transaction. The setSavepoint() method is used to create a new savepoint which refers to the current state of the database within the transaction.
    Syntax:  Savepoint sp= conn.setSavepoint("MysavePoint")
  • releaseSavepoint() method:
    It is used for deleting or releasing the created savepoint.
    Syntax: conn.releaseSavepoint("MysavePoint");


Discussion

No Comment Found