Home » Android » java – How to roll back a transaction on Android?

java – How to roll back a transaction on Android?

Posted by: admin June 15, 2020 Leave a comment

Questions:

Here is the standard idiom for transactions:

   db.beginTransaction();
   try {
     ...
     db.setTransactionSuccessful();
   } finally {
     db.endTransaction();
   }

I want to add a catch block, and I want to issue a rollback. Is it possible, and at all do I need it?

How to&Answers:

You do not need it.

If there is an exception in the ... in your above code, the code you already have will roll back the transaction. The finally {} block is executed after the catch() {} block.