开发者

access .db file from assets in android

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开发者_JAVA技巧.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();
       }


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.


refer these links' answers to copy database from assets:

adding your own SQLite database to an android application

Database not copying from assets

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜