Android 使用事物处理

来源:互联网 发布:数据库份额 编辑:程序博客网 时间:2024/06/06 19:57
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();        }    }}
0 0