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