SQLite的事务管理
发布时间:2020-12-12 20:10:21 所属栏目:百科 来源:网络整理
导读:SQLite的事务 SQLDatabase 提供api可以实现事务功能 如下源码 public void payment(){SQLiteDatabase db = dbOpenHelper.getWritableDatabase();//开启一个事务db.beginTransaction();try{db.execSQL("update person set amount=amount+10 where personid=1"
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"); //设置事务标志-->true db.setTransactionSuccessful(); } //结束事务 commit rollback事务是提交还是回滚是由事务的标志决定的 目前事务的标示是false //事务标志 true-->提交 false-->回滚 finally{ db.endTransaction(); } } 通过上面的代码 可以使用事务 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |