Assume the item list contains item1, item2 and item3. Does the DB insert my items in this order as well?
List<Item> items = ...
List<Map<String, Object>> batchValues = new ArrayList<Map<String, Object>>();
for (Item item : items) {
Map<String, Object> namedParameters = ...
batchValues.add(namedParameters);
}
getNamedParameterJdbcTemplate().batchUpdate(SQL_INSERT_ITEMS, batchValues.toArray(new Map[0]));
Relational databases don’t maintain an insertion order. When you query the records back out you can specify the order you want them in with an
order byclause. If you need the records to be ordered the way you inserted them, you will have to manually store a number into a field on the record. Some databases will have an auto-increment option for a table column, or a sequence generator (Oracle) that you can use.