日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

实例教程七:在SQLite中使用事务

發(fā)布時(shí)間:2025/1/21 数据库 63 豆豆
生活随笔 收集整理的這篇文章主要介紹了 实例教程七:在SQLite中使用事务 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

系統(tǒng)文件管理器
http://www.eoeandroid.com/thread-128567-1-1.html

android 實(shí)現(xiàn)區(qū)域截圖
http://www.eoeandroid.com/thread-149439-1-1.html

影院選坐 寫著玩的
http://www.eoeandroid.com/thread-151980-1-1.html

繼上章
1.在數(shù)據(jù)庫表person添加字段amount
2.在Person類中添加相應(yīng)的amount
3.在PersonService添加payment()方法

public void payment(){SQLiteDatabase db = dbOpenHelper.getWritableDatabase();db.beginTransaction(); //開戶事務(wù)try{db.execSQL("update person set amount=amount-10 where personId=1");db.execSQL("update person set amount=amount-10 where personId=2");db.setTransactionSuccessful(); //設(shè)置事務(wù)的標(biāo)志為True }finally{//為何要加try...catch//因?yàn)樘砑恿薲b.setTransactionSuccessful(),若execSQL中出現(xiàn)問題//則不會(huì)執(zhí)行db.endTransaction() db.endTransaction(); //結(jié)束事務(wù),有2種情況:commit, rollback } //事務(wù)的提交或回滾是由事務(wù)的標(biāo)志決定的//如果事務(wù)的標(biāo)志為True,事務(wù)就會(huì)提交//否則事務(wù)就會(huì)回滾,默認(rèn)情況下事務(wù)的標(biāo)志為false }

4.初始化amount值,便于調(diào)用

public void testUpdateAmount() throws Exception{PersonService service = new PersonService(this.getContext());Person person1 = service.find(1);Person person2 = service.find(2);person1.setAmount(100);person2.setAmount(200);service.update(person1);service.update(person2);}

5.在單元測試類PersonServiceTest中添加測試方法testPayment()

public void testPayment() throws Exception{PersonService service = new PersonService(this.getContext());service.payment();}

?

?

?

與50位技術(shù)專家面對面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的实例教程七:在SQLite中使用事务的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。