安卓开发-事务管理

    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();
    }

你可能感兴趣的:(安卓开发-事务管理)