4

Let me explain my problem precisely i just want to insert 1000's of records in a single shot but it taking some time having some performance issue, is there anyway to improve the performance while doing insert or update operation. Let me explain what i have tried so far :

     public void VisitStatusInsertorUpdate(VisitStatusModel modlobj) {
            String query = " SELECT  * FROM " + VisitStatusModel.table  + " WHERE " + VisitStatusModel.statusid  + "  =" + modlobj.getStatusID() + "";
            Cursor c = db.rawQuery(query, null);
            if (c.moveToFirst()) {
                VisitStatusUpdate(modlobj);
            } else {
                InsertVisit_Status(modlobj);
            }
            c.close();


          }
       private void VisitStatusUpdate(VisitStatusModel modlobj) {
            ContentValues contentValues = new ContentValues();
            String[] args = {String.valueOf(modlobj.getStatusID())};
             contentValues.put(VisitStatusModel.status,modlobj.getStatus());
            contentValues.put(VisitStatusModel.statusid,modlobj.getStatusID());
            db.update(VisitStatusModel.table, contentValues, VisitStatusModel.statusid + "= ?", args);
        }
  private void InsertVisit_Status(VisitStatusModel visitStatusModel) {
        ContentValues contentValues = new ContentValues();
        contentValues.put(VisitStatusModel.status, visitStatusModel.getStatus());
        contentValues.put(VisitStatusModel.statusid, visitStatusModel.getStatusID());
        mcontext.getContentResolver().notifyChange(VisitDAO_URI, null);
        db.insert(VisitStatusModel.table, null, contentValues);
    }

Can someone help me out. Thanks in advance!!

by using the above method i'l do this operation, now how to speed up the process is it the efficient way to do this

Suraj Makhija
  • 1,376
  • 8
  • 16
M.Yogeshwaran
  • 1,419
  • 4
  • 22
  • 48

1 Answers1

1

i just want to insert 1000's

I assume this is one time action, and if so, simply skip this step completely and provide pre-filled database instead. There're libs that can help you with the task of setting your DB from assets like https://github.com/jgilfelt/android-sqlite-asset-helper and others.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141