SQLite的事务管理

来源:互联网 发布:淘宝助手导出数据包 编辑:程序博客网 时间:2024/06/16 07:35

SQLite的事务

SQLDatabase 提供api可以实现事务功能

如下源码
public void payment(){SQLiteDatabase db = dbOpenHelper.getWritableDatabase();//开启一个事务db.beginTransaction();try{db.execSQL("update person set amount=amount+10 where personid=1");db.execSQL("update person set amount=amount-10 where personid=2");//设置事务标志-->truedb.setTransactionSuccessful();}//结束事务  commit rollback事务是提交还是回滚是由事务的标志决定的 目前事务的标示是false //事务标志 true-->提交  false-->回滚finally{db.endTransaction();}}

通过上面的代码 可以使用事务