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

相关文章:

  • 2022-02-09
  • 2021-06-29
  • 2021-06-24
  • 2021-08-29
  • 2022-02-22
  • 2021-07-25
  • 2021-05-08
猜你喜欢
  • 2021-06-26
  • 2021-12-24
  • 2022-12-23
  • 2021-07-04
  • 2021-11-30
相关资源
相似解决方案