首页 > 系统 > Android > 正文

Android数据库SQLite中使用事务

2019-11-09 18:33:09
字体:
来源:转载
供稿:网友
参考链接:http://www.android100.org/html/201502/25/123174.htmlSQLiteDatabase 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}catch(Exception e){    throw(e);}finally{    db.endTransaction();// 结束事务,有两种情况:commit,rollback,    // 事务的提交或回滚是由事务的标志决定的,如果事务的标志为True,事务就会提交,否则回滚,默认情况下事务的标志为False}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表