开发者

How to roll back a transaction on Android?

开发者 https://www.devze.com 2022-12-22 11:08 出处:网络
Here is the standard idiom for transactions: db.beginTransact开发者_开发百科ion(); try { ... db.setTransactionSuccessful();

Here is the standard idiom for transactions:

   db.beginTransact开发者_开发百科ion();
   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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消