0

In my android app user can insert data and when he/she click the save button that inserted data will be saved in sqlite database. I have a predefined database which is in the assets folder (.db file). Now it can save data and I can see that inserted data in eclipse using sqlite manage plugin. But the problem is it cannot update the database in the assets folder. How can I solve this problem ? Can anyone please be so kind enough to explain what should i do ?

Best regards

Thanx in advance

Rose18
  • 2,892
  • 8
  • 47
  • 98

2 Answers2

3

What I want to know is how could I update the database which is in the assets folder after I inserting data.

Editing the Assets folder in runtime is not possible. source.

This Loads the database from the asset folder:

// Copies DB from assests
private void copyDataBase() throws IOException {
    InputStream mInput = mContext.getAssets().open(DB_NAME);
    String outFileName = DB_PATH + DB_NAME;
    OutputStream mOutput = new FileOutputStream(outFileName);
    byte[] mBuffer = new byte[1024];
    int mLength;
    while ((mLength = mInput.read(mBuffer)) > 0) {
        mOutput.write(mBuffer, 0, mLength);
    }
    mOutput.flush();
    mOutput.close();
    mInput.close();
}

See this answer for updating your db from assets.

Community
  • 1
  • 1
amalBit
  • 12,041
  • 6
  • 77
  • 94
  • I already has this method in my DatabaseHelper class, What I want to know is how could I update the database which is in the assets folder after I inserting data. I can see the inserted data in the android system folder (using questoid sqlite manager plugin). Actually, in my android app user should write into the database. – Rose18 Oct 25 '13 at 04:05
2

You can not do any operations on database which you have kept in assets because its just the schema on runtime the database gets copies in data/data/pkg_name/database/myDb.db and changes would be reflected over there not in assets.

Richa
  • 3,165
  • 1
  • 22
  • 26