Exhausting the heap on a JDBC batch with huge size

This is to be expected, but I had never seen it. I increased the batch size on a JDBC batch insert to 100,000 (yes, go ahead and laugh :)), and hit the exception below.

As I noted, it makes sense, I just wanted to note it for future conversations about what happens when, well, you exhaust the memory 🙂

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
        at java.lang.reflect.Array.newArray(Native Method)
        at java.lang.reflect.Array.newInstance(Array.java:52)
        at oracle.jdbc.driver.BufferCache.get(BufferCache.java:282)
        at oracle.jdbc.driver.PhysicalConnection.getCharBuffer(PhysicalConnection.java:14868)
        at oracle.jdbc.driver.OraclePreparedStatement.setupBindBuffers(OraclePreparedStatement.java:3381)
        at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:17086)
        at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:750)
        at loadATG.loadUsers(loadATG.java:185)
        at loadATG.(loadATG.java:30)
        at loadATG.main(loadATG.java:10)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.