1

i have a .db file with 2MB of size. i put it in assets folder in my project. And wrote the code as follow.but i got exception no table exits.please help me How to access .db file without copying into /databases.

db = openOrCreateDatabase("assets\\TDP.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
    db.setVersion(1);
    db.setLocale(Locale.getDefault());
    db.setLockingEnabled(true);
  //  db.execSQL("create table TD_ASSEMBLY(name Text,password Text);");
  Cursor cur = db.query("TD_ASSEMBLY", 
            null, null, null, null, null, null);
       cur.moveToFirst();
       while (cur.isAfterLast() == false) {
         String first= cur.getString(0); 
         String second=cur.getString(1);
         tx.append(first+"  "+second);
         cur.moveToNext();
       }

2 Answers 2

2

Don't use a regular path to retrieve a file from assets. Use getAssets() instead.

The best option is to save it on first run to the database folder in your app. See my answer here: The data disappear after moving the application on a real device in android and the link therein for an example.

Sign up to request clarification or add additional context in comments.

Comments

0

refer these links' answers to copy database from assets:

adding your own SQLite database to an android application

Database not copying from assets

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.