Android数据库SQLite中使用事务

    xiaoxiao2021-03-26  18

    参考链接:http://www.android100.org/html/201502/25/123174.html 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 }catch(Exception e){     throw(e); }finally{     db.endTransaction();// 结束事务,有两种情况:commit,rollback,     // 事务的提交或回滚是由事务的标志决定的,如果事务的标志为True,事务就会提交,否则回滚,默认情况下事务的标志为False }
    转载请注明原文地址: https://ju.6miu.com/read-660082.html

    最新回复(0)