android数据库事务
2015-08-25 18:33
435 查看
直接上代码
public void testTransaction()throws Exception{
//数据库事务
PersonSQLiteOpenHelper helper = new PersonSQLiteOpenHelper(getContext(), "cwj.db", null, 4);
SQLiteDatabase db = helper.getWritableDatabase();
db.beginTransaction();
try {
db.execSQL("update person set account=account+5000 where name=?", new Object[]{"xiaozhui"});
db.execSQL("update person set account=account-5000 where name=?", new Object[]{"mumu"});
db.setTransactionSuccessful();
} finally {
db.endTransaction();
db.close();
}
}
public void testTransaction()throws Exception{
//数据库事务
PersonSQLiteOpenHelper helper = new PersonSQLiteOpenHelper(getContext(), "cwj.db", null, 4);
SQLiteDatabase db = helper.getWritableDatabase();
db.beginTransaction();
try {
db.execSQL("update person set account=account+5000 where name=?", new Object[]{"xiaozhui"});
db.execSQL("update person set account=account-5000 where name=?", new Object[]{"mumu"});
db.setTransactionSuccessful();
} finally {
db.endTransaction();
db.close();
}
}
相关文章推荐
- Android自定义EditText去除边框并添加下划线
- Android:30分钟弄明白Touch事件分发机制
- android 跳转 系统浏览器的方法
- Android 常规任务的高度【schedule】与【scheduleAtFixedRate】差额
- android byte[] 和short[]的转换
- Android Toolbar样式定制详解
- Android Activity生命周期演示程序的例子
- Android 百度地图开发 应用到自己的项目中
- android中跨线程向控件传值的问题
- android代码设置、打开WLAN wifi热点及热点的连接
- Android GridView属性集合
- Android最佳性能实践(二)——分析内存的使用情况
- Android最佳性能实践(一)——合理管理内存
- Android高效加载大图、多图解决方案,有效避免程序OOM
- 【图文】Git学习之十步掌握通过Android Studio整合Git将本地库Push到远程库
- Android最佳性能实践
- Android中图片压缩(质量压缩和尺寸压缩)
- Android中图片压缩(质量压缩和尺寸压缩)
- android:weightSum="2"
- Android应用开发(一):Android平台搭建与开发环境配置