SQLite的Android系统。无法打开数据库文件 [英] SQLite Android . unable to open database file
问题描述
我发现了很多关于这个问题的问题,但我不能修复它。 我的资产文件夹一个SQLite数据库:
资产/数据/数据/ {包名} /databases/mydb.db
我可以打开数据库,并阅读改变一个表结构之前的数据。我尝试卸载应用程序,并重新安装,但我得到了同样的异常。
现在我该怎么办?
在此先感谢
修改
您的应用程序的数据库 //而Android默认的系统路径。
私有静态字符串DB_PATH =/数据/数据/ {mypagackename} /数据库/;
私有静态字符串DB_NAME =mydb.db;
打开数据库(变更表结构前,加入一些领域,这是行不通的)
公共无效的openDatabase()抛出的SQLException {
//打开数据库
字符串mypath中= DB_PATH + DB_NAME;
MyDatabase的= SQLiteDatabase.openDatabase(mypath中,空,
SQLiteDatabase.OPEN_READONLY);
}
看的这个教程
它说明了如何使用preloaded数据库。基本上你不能使用数据库权利的资产,你必须在第一和开放将其复制到内部数据存储在那里。
I found a lot of question about this problem, but i can't fix it. I have a sqlite db in assets folder:
assets/data/data/{package_name}/databases/mydb.db
I can open database and read data before change one table structure. I try to uninstall the app and reinstall again, but i get the same exception.
What can i do now?
Thanks in advance
EDIT
// The Android's default system path of your application database.
private static String DB_PATH = "/data/data/{mypagackename}/databases/";
private static String DB_NAME = "mydb.db";
Open database (Before change table structure, adding some fields, it doesn't work)
public void openDataBase() throws SQLException {
// Open the database
String myPath = DB_PATH + DB_NAME;
myDataBase = SQLiteDatabase.openDatabase(myPath, null,
SQLiteDatabase.OPEN_READONLY);
}
Look at this tutorial
It Explains how to work with preloaded database. Basically you can't use database right from assets, you have to copy it over into internal data storage first and open from there
这篇关于SQLite的Android系统。无法打开数据库文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!