I'm trying to pre generate reports from a very large table(300GB) in PostgreSQL. I do something like this:
rs = stmt.executeQuery("SELECT * FROM tbl");
System.out.println("select all finished");
while (rs.next()) {
/* generate report and save it in report table */
/* generated reports are not in memory,
* They are saved in a summary table in each iteration */
}
When I start the application it gives Exception in thread "main" java.lang.OutOfMemoryError: Java heap space. I tried to use stmt.setFetchSize(1000) But it doesn't solve the problem.
What is the solution? I'm using PostgreSQL 8.4.11 on Debian 6.0.5 and openJDK 6.
[UPDATE]
The printed stack trace shows that the OutOfMemoryError exception has been generated in rs = stmt.executeQuery("SELECT * FROM tbl"); line. Also System.out.println("select all finished"); never shows.
- I'm running in
autocommitmode. stmt.getResultSetConcurrency()returns 1007.stmt.getResultSetHoldability()return 2.rs.getType()returns 1003.