3 choices:
1) make your java heap size big enough to hold the entire ResultSet. If you're using Sun's Java (almost everyone does), then you increase the maximum heap with the -Xmx parameter whent the JVM is started. It looks like you're using the default maximum, which is pretty small. See:
http://java.sun.com/j2se/1.3/docs/tooldocs/solaris/java.html☞ VM 힙사이즈를 늘린다는 내용인데 물리적 메모리는 한계가 있기 때문에 초대용량으로 넘어갈때는 사용하기 힘들다.
2) retrieve the ResultSet from the database incrementally, and process it incrementally. Statement.setFetchSize() suggests to the driver how much of the ResultSet to keep in memory (and to retrieve in one chunk from the database), but it's common for scrollable ResultSets to ignore this hint and try to keep everything in memory. A ForwardOnly ResultSet (the default) is more likely to work incrementally, but it depends totally on your driver.
☞ 점진적으로 데이터를 가져오도록 세팅한다. 이렇게 하면 전체 메모리에 데이터를 가져오지 않으므로 부담이 적어진다.
3) break the data into multiple queries....
☞ 다중쿼리로 데이터를 쪼갠다. 단계별로 쿼리를 분리하면 데이터베이스 전체성능에 부담을 줄일 수 있다.
출처: http://forum.java.sun.com/thread.jspa?forumID=48&threadID=745523