Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在Sqlite数据库中,如何同时在表中插入多行_Android_Sqlite_Insert - Fatal编程技术网

Android 在Sqlite数据库中,如何同时在表中插入多行

Android 在Sqlite数据库中,如何同时在表中插入多行,android,sqlite,insert,Android,Sqlite,Insert,如何在Sqlite数据库中同时插入多行?我正在使用Android和Java。ContentValues=newcontentvalues(); ContentValues values = new ContentValues(); for(int i = 0; i<=5; i++) { values.put(COLUMN_NAME, i); values.put(COLUMN_NAME, 0); db.insert(TABLE_NAME, null, values)

如何在Sqlite数据库中同时插入多行?我正在使用Android和Java。

ContentValues=newcontentvalues();
ContentValues values = new ContentValues();
for(int i = 0; i<=5; i++) {
    values.put(COLUMN_NAME, i);
    values.put(COLUMN_NAME, 0);
    db.insert(TABLE_NAME, null, values);
}

对于(int i=0;i您正在寻找的是
bulkInsert
。它将允许您提供一个
ContentValues
数组来插入。有关更多信息,请参阅Android文档:


您可以使用inserthelper,但请查看这篇非常古老的帖子。当您尝试对数据库进行多次调用(如更新或插入)时,请使用事务处理。这将大大提高速度

db.beginTransaction();
try
{
    while(...) 
    {
        // .. do your inserts, updates and deletes here
    }

    // If successful commit those changes
    db.setTransactionSuccessful();
}
finally 
{
    db.endTransaction();
}

在哪种编程语言中?这是否有效?您不能用一个请求写入所有行吗?
InsertHelper
现在已被弃用。需要注意的是,文档中说:“此函数不能保证插入的原子性。”但是我找不到更好的方法来插入多行。你能解释一下这会有什么影响吗?