SQLite 数据批量操作

前端之家收集整理的这篇文章主要介绍了SQLite 数据批量操作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

记录一下sqlite批量操作的写法

  1. try {
  2. sqliteDatabase db = DBHelper.getDatabase();
  3. String sql = "INSERT INTO " + TABLE + "(col_1,col_2,col_3)VALUES(?,?,?)";
  4. sqliteStatement statement = db.compileStatement(sql);
  5. db.beginTransaction();
  6. for (Object item : items) {
  7. statement.bindString(1,item.val_1);
  8. statement.bindString(2,item.val_2);
  9. statement.bindString(3,item.val_3);
  10. statement.executeInsert();
  11. }
  12. db.setTransactionSuccessful();
  13. } catch (Exception e) {
  14. e.printStackTrace();
  15. } finally {
  16. db.endTransaction();
  17. }

猜你在找的Sqlite相关文章