0

i am developing android app, here i am having an huge no of data approximately 10000 records with 10 fields in the server, i need to get this data and store it in the my local db, so for this i tried to implement by getting the data in the form of json parsing it and inserting in db one by one, it is taking less time to download the data but more time to insert to the db, after some time i get to know that i am inserting to the db one by one, so insertion operations looping based on the total no of records which had been got. i tried to look for the alternatives i could not get the way for this, so i request you to give me suggestions and snippets to me achieve this.

Thanking you

Dayanand
  • 5
  • 3

1 Answers1

0

use transactions to wrap multiple inserts into one operation, that's a lot faster: Improve INSERT-per-second performance of SQLite?

List<Item> list = getDataFromJson();
SQLiteDatabase db = getDatabase();

db.beginTransaction();
try {
    // doing all the inserts (into memory) here
    for(Item item : list) {
        db.insert(table, null, item.getContentValues());
    }
    // nothing was actually inserted yet
    db.setTransactionSuccessful();
} finally {
    // all inserts happen now (if transaction was set to successful)
    db.endTransaction();
}
Community
  • 1
  • 1
zapl
  • 63,179
  • 10
  • 123
  • 154