public void testTrasaction() throws Exception{
  PersonSQLiteOpenHelper helper = new PersonSQLiteOpenHelper(getContext());
  SQLiteDatabase db = helper.getWritableDatabase();
  db.beginTransaction();
  try{
   db.execSQL("update sys_user set account = account-500 where name=?",new Object[]{"zhangsan"});
   
   db.execSQL("update sys_user set account = account+500 where name=?",new Object[]{"lisi"});
   //标记数据库事务执行成功。
   db.setTransactionSuccessful();
  }catch(Exception e)
  {
   Toast.makeText(getContext(), "转账出错!", Toast.LENGTH_LONG).show();
  }
  
  finally{
   db.endTransaction();
   db.close();
  }

posted on 2015-01-18 19:18  ~向阳花~  阅读(417)  评论(0编辑  收藏  举报