0

I have e following codes to add a single entry into the database. However it takes more then 5 sec for the insertion to complete. I have tried using transaction as well and the performance is marginally better. Is there a way to speed up the insertion time ?

    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put("name", username); 

    db.beginTransaction();
    Log.e(TAG,"START");
    // slow insertion
    db.insert("user", null, values);
    Log.e(TAG,"END");       
    db.setTransactionSuccessful();
    db.endTransaction();

    db.close(); 

The 5 sec i observed is from the logcat ouput.

Thanks.

sean
  • 717
  • 2
  • 9
  • 23
  • Are you connecting to the SQLite database over a 300 baud modem? I still don't think it would take 5 minutes. Is your hard drive failing? Do other queries succeed? What do the successful queries look like? – Robert Harvey Jun 23 '14 at 05:16
  • http://stackoverflow.com/questions/1711631/how-do-i-improve-the-performance-of-sqlite – ngrashia Jun 23 '14 at 05:17
  • @RobertHarvey It is not taking 5 min, it is 5 seconds. You read it wrong I think – N Sharma Jun 23 '14 at 05:18
  • Hi , I am running it on an android device. The insertion is successful but it just takes approx 5 seconds. The insertion occurs only when a new user account is created. Therefore i am not doing bulk insertion. – sean Jun 23 '14 at 05:23
  • When are you opening the database for use? I suggest you should open it in "onResume". – Karioki Jun 23 '14 at 05:40
  • Do you have any complex triggers or indexes in your table? Is this a table or a view? – cha Jun 23 '14 at 05:41
  • @cha Just a simple table for storing index , username and password. – sean Jun 23 '14 at 05:43
  • @arjun.9990 Currently my program only have a login screen. I am opening the database in onCreate – sean Jun 23 '14 at 05:43

0 Answers0