Fastest way to iterate through large table using JDBC

前端 未结 3 1141
名媛妹妹
名媛妹妹 2020-12-07 23:07

I\'m trying to create a java program to cleanup and merge rows in my table. The table is large, about 500k rows and my current solution is running very slowly. The first thi

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-07 23:40

    One thing that helped me was Statement.setFetchSize(Integer.MIN_VALUE). I got this idea from Jason's blog. This cut down execution time by more than half. Memory consumed went down dramatically (as only one row is read at a time.)

    This trick doesn't work for PreparedStatement, though.

提交回复
热议问题