Android 使用事物处理

public class DBTransation {

    public void transationTest(Context context){
        DBHelper helper  = new DBHelper(context);
        SQLiteDatabase db = helper.getWritableDatabase();
        try {
            db.beginTransaction();
            db.execSQL("update book set price = price * 2 where id = ?", new Object[]{"1"});
            db.setTransactionSuccessful();
        } catch (Exception e) {
            e.printStackTrace();
        } finally{
            db.endTransaction();
            db.close();
        }


    }
}

你可能感兴趣的:(android,事物处理)