Wael Wael - 1 year ago 51
Java Question

I am getting java heap space error while inserting a record to the database?

I am getting a java heap space error but while trying to insert a record to the database. I am not sure how come oracle is able to consume the heap and why it is consuming this much. The error is occuring on this line:

Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
String sqlString = null;
DaoUtility dUtil = DaoUtility.getInstance();

con = dUtil.getConnection();
. . .

Here is the log:

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:226)
at oracle.jdbc.driver.PhysicalConnection.getCharBuffer(PhysicalConnection.java:7643)
at oracle.jdbc.driver.OraclePreparedStatement.setupBindBuffers(OraclePreparedStatement.java:2949)
at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:2355)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3571)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3657)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1350)
at weblogic.jdbc.wrapper.PreparedStatement.executeUpdate(PreparedStatement.java:172)

Answer Source

Oracle JDBC driver is notorious for memory consumption. Please read about the configuration parameters available to you to control its memory consumption. Especially take note of oracle.jdbc.maxCachedBufferSize for your case.