简体   繁体   English

Android多记录SQLite

[英]Android multiple record SQLite

I saw in the SQLite documentation that you can not insert multiple records at the same time. 我在SQLite文档中看到您不能同时插入多个记录。 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 . 例如,我有2 TEXT fields ,同时我想在filed1中插入10 recordsdate从今天到10天),并在field2中将50 was added in the 10 record50 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());
...

for that you have to use for loop or anything 为此,您必须使用for循环或其他任何东西

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 你可以像我用过的那样使用循环

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM