【发布时间】:2013-12-03 15:07:27
【问题描述】:
我需要更新超过 60k 行的表的每一行。 目前我正在这样做:
public void updateRank(Map<Integer, Double> map) {
Iterator<Map.Entry<Integer, Double>> it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Integer, Double> pairs = (Map.Entry<Integer, Double>) it.next();
String query = "update profile set rank = " + pairs.getValue()
+ " where profileId = " + pairs.getKey();
DBUtil.update(query);
it.remove();
}
}
仅此方法大约需要 20 多分钟才能完成,我认为每行 (60k) 的数据库都是我认为的原因。(尽管我使用 dbcp 进行连接池,最大活动连接数为 50)
如果我能够通过单个数据库命中来更新行,那就太好了。那可能吗 ?怎么样?
或者有什么其他的方法来改善时间?
【问题讨论】: