我正在尝试从一个非常大的PostgreSQL表(300GB)中预生成报告。我会做类似这样的事情:
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 */
}
当我启动应用程序时,它会显示
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
。我尝试使用stmt.setFetchSize(1000)
,但它并不能解决问题。有什么解决方法吗?我正在Debian 6.0.5上使用PostgreSQL 8.4.11和openJDK 6。 [更新] 打印的堆栈跟踪显示
OutOfMemoryError
异常在rs = stmt.executeQuery("SELECT * FROM tbl");
行中生成。同时System.out.println(“select all finished”);
从未出现。
- 我正在运行
autocommit
模式。 stmt.getResultSetConcurrency()
返回1007。stmt.getResultSetHoldability()
返回2。rs.getType()
返回1003。