Copy codeThe Code is as follows: public void payment (){
SQLiteDatabase db = dbOpenHelper. getReadableDatabase ();
Db. beginTransaction (); // start the transaction
Try {
Db.exe cSQL ("update person set amount = amount-10 where personid = 2 ");
Db.exe cSQL ("update person set amount = amount + 10 where personid = 5 ");
Db. setTransactionSuccessful (); // set the transaction flag to true. Calling this method will commit the transaction when the endTransaction () method is executed. If this method is not called, it will be executed to endTransaction () method to roll back the transaction.
} Catch (SQLException e ){
} Finally {
Db. endTransaction ();
}
// Terminate the transaction in two cases: commit, rollback,
// The transaction commit or rollback is determined by the transaction flag. If the transaction flag is true, the transaction will be committed. Otherwise, the rollback is performed. By default, the transaction flag is false.
}
PS: similar to the transfer function, two operations are completed in the same transaction.