android数据库事务

来源:互联网 发布:牙签弩淘宝多少钱 编辑:程序博客网 时间:2024/04/30 04:21

直接上代码

public void testTransaction()throws Exception{//数据库事务PersonSQLiteOpenHelper helper = new PersonSQLiteOpenHelper(getContext(), "cwj.db", null, 4);SQLiteDatabase db = helper.getWritableDatabase();db.beginTransaction();try {db.execSQL("update person set account=account+5000 where name=?", new Object[]{"xiaozhui"});db.execSQL("update person set account=account-5000 where name=?", new Object[]{"mumu"});     db.setTransactionSuccessful();   } finally {     db.endTransaction();     db.close();   }}


0 0
原创粉丝点击