码迷,mamicode.com
首页 > 数据库 > 详细

Sqlite数据库中的事务

时间:2015-01-18 19:43:33      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:

 

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

Sqlite数据库中的事务

标签:

原文地址:http://www.cnblogs.com/zhangruiBlog/p/4232105.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!