安卓开发-事务管理

    public void change(View view){
        StudentOpenHelper studentOpenHelper=new StudentOpenHelper(this);
        SQLiteDatabase sqLiteDatabase=studentOpenHelper.getWritableDatabase();
        sqLiteDatabase.beginTransaction();
        try{
            sqLiteDatabase.execSQL("update money set account=account+1000 where name='张三'");
            sqLiteDatabase.execSQL("update money set account=account-1000 where name='李四'");
            sqLiteDatabase.setTransactionSuccessful();
        }catch (Exception e){
            sqLiteDatabase.endTransaction();
        }
        sqLiteDatabase.close();
    }

猜你喜欢

转载自blog.csdn.net/hhyihquk1/article/details/80515620