SQlite unable to open
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.
精彩评论