Android SQLite 事物操作

  1. public void payment(){ 
  2.         SQLiteDatabase db = dbOpenHelper.getWritableDatabase(); 
  3.         db.beginTransaction();//开启事务 
  4.         try
  5.             db.execSQL("update person set amount=amount-10 where personid=?", new Object[]{1}); 
  6.             db.execSQL("update person set amount=amount+10 where personid=?", new Object[]{2}); 
  7.             db.setTransactionSuccessful();//设置事务标志为成功,当结束事务时就会提交事务 
  8.         }finally
  9.             db.endTransaction(); 
  10.         } 
  11.     } 

你可能感兴趣的:(Android优化,android开发实用)