I need to update every row of a table having more then 60k rows. Currently I'm doing it like this:
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();
}
}
This method alone took around 20+ mins to complete, hitting the database for each row(60k) is what i think the reason here.(though i'm using dbcp for connecton pooling, with 50 maximum active connections)
It'd be great if i'd be able to update rows with single database hit. Is that Possible ? How ?
Or any other way to improve timing here ?