0

I saw in the SQLite documentation that you can not insert multiple records at the same time. For example, I have 2 TEXT fields and at the same time I want to insert in filed1 10 records with the date that goes from today to 10 days, and in the field2 value of 50 was added in the 10 record. I hope I explained. Now normally I insert the record in this way:

public void insertDb(View v) {
ContentValues cv = new ContentValues();
cv.put(Table.ONE, mNe.getText().toString());
cv.put(Table.ONE, mNel.getText().toString());
...
user3160725
  • 1,801
  • 3
  • 15
  • 14

1 Answers1

0

for that you have to use for loop or anything

like below code

public void add_device(String data,
        ArrayList<HashMap<String, String>> jsonlist) {

    try {

        database = this.getWritableDatabase();
        for (HashMap<String, String> map : jsonlist) {

            ContentValues values = new ContentValues();
            values.put(SAVE_COLUMN_NAME, data);
            values.put(SAVE_COLUMN_KEY, map.get(SAVE_COLUMN_KEY));
            values.put(SAVE_COLUMN_VALUE, map.get(SAVE_COLUMN_VALUE));
            Long int1 = database.insertOrThrow(SAVE_TABLE_NAME, null,
                    values);
            Log.i("inserted value", values + "");
            Log.i("insserted value ", int1 + "");
        }

    }

    catch (Exception e) {

    }
}

you can use loop like i have used

Ando Masahashi
  • 3,112
  • 2
  • 24
  • 41