http://www.outofwhatbox.com/blog/2010/12/android-using-databaseutils-inserthelper-for-faster-insertions-into-sqlite-database/
This is a good article.
two ways to do batch insert:
The second one is really helpful,because i want to insert the records with the field index and without knowing the field name .
This is a good article.
two ways to do batch insert:
try{
db.beginTransaction();
for each record in the list {
do_some_processing();
if (line represent a valid entry) {
db.insert(SOME_TABLE, null, SOME_VALUE);
}
some_other_processing();
}
db.setTransactionSuccessful();
} catch (SQLException e) {
} finally {
db.endTranscation();
}
try {
mDb.beginTransaction();
InsertHelper ih = new InsertHelper(db, "columnTable");
for (Value value : values) {
ih.prepareForInsert();
ih.bind(colIdx, value.getSomeValue());
// ...
ih.execute();
}
mDb.setTransactionSuccessful();
} finally {
mDb.endTransaction();
}
The second one is really helpful,because i want to insert the records with the field index and without knowing the field name .
本文介绍了两种使用Android DatabaseUtils Inserthelper进行SQLite数据库批量插入的方法。第一种方式通过开启事务并逐条插入记录;第二种利用InsertHelper简化字段绑定过程,适用于已知字段索引但未知字段名的情况。
5910

被折叠的 条评论
为什么被折叠?



