Java out of memory using PostgreSQL
- Set the fetch size to something reasonable (
st.setFetchSize(rowCount)
). You can experiment with this. - Put everything in a transaction with autocommit off (
con.setAutoCommit(false)
).
See this explanation and the documentation.