title: Java out of memory using PostgreSQL
body: <p>There is another possibly related question on this but it didn't have answers and the asker didn't clarify any.</p>
  
  <p>So when I'm going over a large result set in postgres, java seems to break.</p>
  
  <p>The query I'm running is trying to get around 5.5M rows. Basically I'm trying to populate a Neo4J database from a Postgres db.</p>
  
  <p>I won't bother posting the code unless someone asks as it's pretty generic I think. Here is the exception output:</p>
  
  <pre><code>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.&lt;init&gt;(Unknown Source)
      at java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(Unknown Source)
      at java.sql.SQLException.&lt;clinit&gt;(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)
  </code></pre>
  
  <p>Line 52 is just the query, as so:</p>
  
  <pre><code>rs = st.executeQuery("select player_lo, player_hi, total_hands_lo, total_hands_hi, (pc_lo + pc_hi)/2 as avg_pc from pair");
  </code></pre>
  
  <p>So I guess rs is getting pretty big. I suppose I could just use LIMIT and OFFSET and run the program a few hundred times or have it reset rs in a loop or so, but I'd rather not have to.</p>