开发者

Using existed SQLite database in Android

开发者 https://www.devze.com 2023-03-28 11:08 出处:网络
My problem is in using the existed sqlite-database in my android application. To manage it, I used the well-known article, that describes my task - http://www.reigndesign.com/blog/using-your-own-sqlit

My problem is in using the existed sqlite-database in my android application. To manage it, I used the well-known article, that describes my task - http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications

While this app starts, I'm getting the error:

08-17 06:35:18.416: ERROR/Database(286): sqlite3_open_v2("data/data/com.jeston.existed.sqlite/databases/android_test_db.db", &handle, 1, NULL) failed
08-17 06:35:18.437: ERROR/AndroidRuntime(286): Uncaught handler: thread main exiting due to uncaught exception
08-17 06:35:18.457: ERROR/AndroidRuntime(286): android.database.sqlite.SQLiteExc开发者_Python百科eption: unable to open database file 

I suspect that I use wrong path to mydatabase.I put down my android_test_db file to assets folder and, as written in the blog, gave the

private final static String DB_PATH = "data/data/com.jeston.existed.sqlite/databases/";
private final static String DB_NAME = "android_test_db.db";

So, my question is these pathes are correct or no? or may be, i'm on the wrong way in common?

thanks for everyone.


The db name extension has to be exactly the same as it is. Moreover, I think your main problem is that you specify the wrong package. It has to be the root package. Try that:

private final static String DB_PATH = "data/data/com.jeston.existed/databases/";


the openDataBase method should look like this:

 public void openDataBase() throws SQLException{
    //Open the database
    String myPath = DB_PATH + DB_NAME;
    myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
}

use SQLiteDatabase.NO_LOCALIZED_COLLATORS instead of SQLiteDatabase.OPEN_READONLY

0

精彩评论

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