开发者

SQlite unable to open

开发者 https://www.devze.com 2023-03-23 19:01 出处:网络
I create my database using sqliteadmin (version 0.8.3.2),I place this file into my asset directory and then copy this file into data/data/mypackage/databases/mydb,its ok.now when I am trying to open

SQlite unable to open

I create my database using sqliteadmin (version 0.8.3.2),I place this file into my asset directory and then copy this file into data/data/mypackage/databases/mydb,its ok.now when I am trying to open this file getting exception as android.database.sqlite.SQLiteException: unable to open da开发者_Python百科tabase file,below code i am using to open the mydb.

private static final String DB_PATH = "/data/data/src.com/databases/";
private static final String DB_NAME = "mydb";
String mypath = DB_PATH + DB_NAME;

try{ 
dbBF = SQLiteDatabase.openDatabase(mypath, null, SQLiteDatabase.OPEN_READWRITE);

}catch(Exception ex)

{System.out.print("H![enter image description here][1]ere is an Exception"+ex);
}    
Cursor cur = dbBF.rawQuery("SELECT * FROM"+"myTable" , null);


Your approach seems right. Do you have extension on the your database file? Like mydb.db. If you do than you should add it complete name of the file.


I had the same problem. First please note that your database file should not be bigger than 1.2MB, and if it's, then try to split it. Second, instead of the following lines,

DBAdapter db = new DBAdapter(this);
db.openDataBase(); //Bad! db not created yet!

try to use

DBAdapter db = new DBAdapter(this);
db.createDataBase(); //needs exception handling
db.openDataBase();

I copied it from How does android access a sqlite database included in the assets folder . Anyway, it works for me. In case of any problem, let me know.

0

精彩评论

暂无评论...
验证码 换一张
取 消