SQL批量更新保证顺序?
假设项目列表包含项目1、项目2和项目3。数据库是否也按此顺序插入我的项目?
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]));
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]));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然可以,不然就太没价值了。
顺便说一句,您应该更改此代码
:
Of course it does, otherwise it would be pretty worthless.
And by the way, you should change this code:
to
关系数据库不维护插入顺序。当您查询记录时,您可以使用
order by
子句指定您想要的顺序。如果您需要按照插入记录的方式对记录进行排序,则必须手动将数字存储到记录的字段中。某些数据库将为表列提供自动增量选项,或者您可以使用序列生成器 (Oracle)。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 by
clause. 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.