public void inertOrUpdateDateBatch(List<String> sqls) {
SQLiteDatabase db = getWritableDatabase();
db.beginTransaction();
try {
for (String sql : sqls) {
db.execSQL(sql);
}
// 设置事务标志为成功,当结束事务时就会提交事务
db.setTransactionSuccessful();
} catch (Exception e) {
e.printStackTrace();
} finally {
// 结束事务
db.endTransaction();
db.close();
}
}
db.beginTransaction(); // 手动设置开始事务
for (ContentValues v : list) {
db.insert("bus_line_station", null, v);
}
db.setTransactionSuccessful(); // 设置事务处理成功,不设置会自动回滚不提交
db.endTransaction(); // 处理完成
db.close()
InsertHelper ih = new InsertHelper(db, "userApps");
db.beginTransaction();
final int idColumnIndex = ih.getColumnIndex("id_");
final int nameColumnIndex = ih.getColumnIndex("name");
final int downloadTimesColumnIndex = ih.getColumnIndex("downloadTimes");
final int pkgNameColumnIndex = ih.getColumnIndex("pkgName");
try {
for (XCSoftwareItem item : userappList) {
ih.prepareForInsert();
ih.bind(idColumnIndex, item.id);
ih.bind(nameColumnIndex, item.name);
ih.bind(downloadTimesColumnIndex, item.downloadTimes);
ih.bind(pkgNameColumnIndex, sitempkgName);
ih.execute();
}
db.setTransactionSuccessful();
} finally {
ih.close();
db.endTransaction();
db.close();
}
String sql = "insert into userApps(id_,pkgName,name,downloadTimes) values(?,?,?,?)";
SQLiteStatement stat = db.compileStatement(sql);
db.beginTransaction();
for (XCSoftwareItem item : userAppsList) {
stat.bindLong(1, item.id);
stat.bindString(2, item.pkgName);
stat.bindString(3, item.name);
stat.bindLong(4, item.downloadTimes);
stat.executeInsert();
}
db.setTransactionSuccessful();
db.endTransaction();
db.close();