android - What is fastest way to insert rows in sqlite database -


i have around 7000 rows want insert device's(android galaxy tab2) sqlite database. parsing json file , inserting row database using "for" loop. taking more 120 seconds parse , inset data sqlite database. there other faster way this?

thanks...

i have ran exact same situation. first using databaseutil.inserthelper, , taking me +30 seconds 600 entries.

i did bit more digging , found out every row i'm inserting being committed, extremely expensive.

to solve this, switched ormlite, insertall method:

/** * inserts multiple objects database committing them @ once * * @param objects objects insert */ public void insertall(final t[] objects) {     try {         dao.callbatchtasks(new callable<void>() {          @override         public void call() throws exception {             (t object : objects) {                 dao.create(object);             }             return null;             }         });     } catch (exception e) {     adblogger.error("error inserting new " + classname + "s in database"); } } 

the idea here insert of array of object, @ end 1 big commit. after switch insert became instantanious.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -