安卓 SQLite error:SQLite database locked exception while compling : PRAGMA journal_mode .....
项目中频繁的切换Tab键,会频繁地从数据库读取数据,这是报出这样的错误:
解决方法是在国外的某论坛找到的 :
在插入数据的时候,首先:
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(f, null);
db.beginTransaction(); ////开启一个事务
db.insert(HJZ_SQLiteOpenHelper.TABLE_NAME_KP, null, cv);
db.setTransactionSuccessful(); //必须加这一句,否则插入不了数据
db.endTransaction(); ////关闭一个事务
db.close();
原因:是4.0以前的版本db.close();会结束事务,而Jelly Bean 以后的版本因为安全性的问题,必须结束即endTransactiony以后才能再次访问本地数据库。哎。。苦逼的百度啊。。另外,吐槽一下不向下兼容的Android
PS:android中,对数据库进行批量操作时,建议先打开会话:
db.beginTransaction();
//批量insert或者update等
db.setTransactionSuccessful();
db.endTransaction();
这样之后,在大数据量的处理是灰常的高效,
实际中,减少了3~10倍的时间。
另外,在重写ContentProvider时,不要针对数据的读写加同步了,因为底层数据库已经做了同步保护,上层再加上同步保护多余,而且非常影响效率。
安卓 SQLite error:SQLite database locked exception while compling : PRAGMA journal_mode .....的更多相关文章
- sqlite: Error Code : 5 (SQLITE_BUSY) (database is locked (code 5): , while compiling: PRAGMA journal_mode)
今天遇到了一个很奇怪的问题,登录完成后,程序会莫名crash, 报了下面的错误: sqlite: Error Code : (SQLITE_BUSY) (database is locked (cod ...
- Android多线程操作sqlite(Sqlite解决database locked问题)
参考http://blog.csdn.net/sdsxleon/article/details/18259973 很好 https://github.com/2point0/Android-Data ...
- SQLITE报错database is locked的解决办法
用firedac连接SQLITE数据库,空间tdbedit绑定字段name,如下语句修改其值时报错. procedure TForm1.Button3Click(Sender: TObject);be ...
- android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error(Sqlite code 14): Could not open database,(OS error - 13:Permission denied)
07-24 15:03:14.490 6291-6291/com.tongyan.nanjing.subway E/SQLiteDatabase: Failed to open database '/ ...
- svnkit 异常:Exception in thread "main" org.tmatesoft.svn.core.SVNException: svn: E200030: SQLite error
https://stackoverflow.com/questions/16063105/org-tmatesoft-sqljet-core-sqljetexception-busy-error-co ...
- Sqlite 数据库出现database disk image is malformed报错的解决方法
软件用的是Sqlite数据库,昨天还好好的,今天开机登录软件报错:database disk image is malformed 用Sqlite Expert Personal 重建索引,发现其中一 ...
- SQLite打开提示database disk image is malformed
SQLite打开提示database disk image is malformed 网上说产生这种错误的原因有很多种,磁盘空间不足,还有就是写入数据过程中突然掉电等. 这种情况,如果数据还可以导出, ...
- SQLite EF Core Database Provider
原文链接 This database provider allows Entity Framework Core to be used with SQLite. The provider is mai ...
- Create schema error (unknown database schema '')
Andrey Devyatka 4 years ago Permalink Raw Message Hi,Please tell me, can I use the static library in ...
随机推荐
- EnglishWords----1
upon在...上面 upright垂直的,直立的 upward向上的 outward外面的,向外的 downward向下的 vertical垂直的 parallel平行的 sow播种 cut切 ch ...
- Using Sphinx to index CNS database
1, look at the sphinx.person.address.conf to see how to configure the conf file2, index the database ...
- how to enable #ifdef macro in the command line of make?
Compilers normally use the -D flags eg Code: test.o: test.cpp $(CC) $(CFLAGS) -DTEST1 test.cpp -o $@
- BNU OJ 51003 BQG's Confusing Sequence
二进制++高精度取模 #include<cstdio> #include<cstring> #include<algorithm> using namespace ...
- Mysql主从复制(基于Log)
Master(主)操作 实验机:两台 IP:192.168.1.5 192.168.1.10 操作系统:Linux RedHat 6.5 Mysql版本:5.6.31 # vim /etc ...
- (中等) CF 555E Case of Computer Network,双连通+树。
Andrewid the Android is a galaxy-known detective. Now he is preparing a defense against a possible a ...
- javascript第一篇----使用简介
使用技巧 Javascript加入网页有两种方法:直接方式和引用方式. 直接方式 直接调用分为两种形式:代码块和代码行 代码行引用: <a href="javascript:alert ...
- phpstrom 2016.2 注册服务器地址
无意中发现的,亲测可用:http://114.215.133.70:41017
- tcpdump的表达元
(nt: True 在以下的描述中含义为: 相应条件表达式中只含有以下所列的一个特定表达元, 此时表达式为真, 即条件得到满足) dst host host如果IPv4/v6 数据包的目的域是host ...
- Codeforces#362
A题 题意:给定一串数列,t,t+s,t+s+1,t+2s,t+2s+1......问某一个数是否是数列当中的 题意:只需判断(x-t)与(x-t-1)能否整除s即可,注意起始时的判断 #includ ...