这里有一个可能相关的问题,但是它没有答案,而且提问者也没有做任何澄清。
所以当我在postgres中查找大量结果时,java似乎会崩溃。
我运行的查询尝试获取约550万行。基本上,我正在尝试从Postgres数据库填充Neo4J数据库。
除非有人要求,否则我不会发布代码,因为我认为它很普通。以下是异常输出:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Unknown Source)
at java.lang.Class.getDeclaredField(Unknown Source)
at java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl.<init>(Unknown Source)
at java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(Unknown Source)
at java.sql.SQLException.<clinit>(Unknown Source)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1818)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:512)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:374)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:254)
at sqlToGraph.SqlToGraph.main(SqlToGraph.java:52)
第52行只是查询语句,如下所示:
rs = st.executeQuery("select player_lo, player_hi, total_hands_lo, total_hands_hi, (pc_lo + pc_hi)/2 as avg_pc from pair");
我猜rs变得相当大了。我想我可以使用LIMIT和OFFSET并运行程序几百次,或在循环中重置rs,但我宁愿不这样做。