安卓 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 ...
随机推荐
- 《Peering Inside the PE: A Tour of the Win32 Portable Executable File Format》阅读笔记二
Common Sections The .text section is where all general-purpose code emitted by the compiler or assem ...
- MFC添加背景图片三种方法
方法一: 1.声明成员变量CBrush m_brush;2.在InitDialog中添加代码: ? CBitmap bmp; bmp.LoadBitmap(IDB_BITMAP1); //IDB_B ...
- 属性动画ValueAnimator用法
用法举例: 1. ValueAnimator animator = ValueAnimator.ofInt(0,100);//定义animator 2. animator.addUpdateListe ...
- spring MVC之返回JSON数据(Spring3.0 MVC)
方式一:使用ModelAndView的contentType是"application/json" 方式二:返回String的 contentType是&qu ...
- Android面试经验1
1,java基本数据类型. Byte.short.int.long.float.double.char.boolean. 1 2 2 2 4 ...
- bundle export fail
C:\eclipse\eclipse.exe -vmargs -Dfile.encoding=utf8
- SQL求解两个时间差
sql 求解两个时间差 SELECTDATEDIFF( Second, '2009-8-25 12:15:12', '2009-9-1 7:18:20') --返回相差秒数 SELECTDATEDIF ...
- javascript 用call来继承实例属性
xxx.call(thisObj, arg1,...)的调用可以改变当前函数的执行环境为传入的thisObj对象.利用这一点可以实现继承————当前的对象获得XXX的属性和方法. 例子: functi ...
- ArrayList和数组间的相互转换
开发中不免碰到List与数组类型之间的相互转换,举一个简单的例子: package test.test1; import java.util.ArrayList; import java.util.L ...
- 文件I/O的操作实例
1_open.c: #include <sys/types.h> #include <stdio.h> #include <sys/stat.h> #include ...