代码如下
publicvoidpayMent(){
sqliteDatabase dbOperate = dbOpenHelper.getWritableDatabase();
//开启事务
dbOperate.beginTransaction();
try{
String sql2 ="update person set amount = amount- 10 where personid = 2";
String sql3 ="update person set amount = amount+ 10 where personid = 3";
设置事务的标志为true
dbOperate.setTransactionSuccessful();
} finally{
结束事务
事务的提交或回滚是由事务的标志界定的,默认情况下事务的标志为false,如果事务的标志为true,事务就会回滚
dbOperate.endTransaction();
}
}
原文链接:https://www.f2er.com/sqlite/201197.html