0

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.SQLiteException: 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.

2 Answers 2

2

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/";
Sign up to request clarification or add additional context in comments.

3 Comments

Seems to be, no - becouse of after this change I've got the mistake: unable to open database file. in experience way, i've localized the error in my method: public int getCountRecords() { Cursor c = myDB.query(DB_NAME, new String[] {"_id","name","age"}, null, null, null, null, null); return c.getCount(); }; this method throws the exception - no such table "android_test_table"
oh right, but why do you query on DB_NAME? The first parameter of query(...) has to be the table name.
Yeeeh, your right, absolutely.Thanks, problem was in that my first argument was database's name and not table's name.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.