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"); db.setTransactionSuccessful();//设置事务标志为true }finally{ db.endTransaction();//结束事务 事务的提交或回滚使用事务的标志决定的,如果事务表示为TRUE就提交否则就回滚,默认情况下事务的标志位FALSE }
android第十五步在SQLite中使用事物,布布扣,bubuko.com
原文:http://www.cnblogs.com/zyldream/p/3604847.html