JDBC Statement for a Query Using a Stored Procedure with a Character Return or OUT Parameter will use Maximum Buffer Size Leading to Large JVM Memory Use or OutOfMemoryError

(Doc ID 1480013.1)

Last updated on AUGUST 02, 2017

Applies to:

JDBC - Version 11.2.0.3.0 and later
Information in this document applies to any platform.

Symptoms

A JDBC application is found to use an excessive amount of JVM memory when executing a JDBC query that calls a stored procedure / function with a character return.  The result set meta data shows that the selected character expression is allocated the maximum buffer size even when the expected result is quite small.

This may ultimately lead to either a very slow execution of even an out of memory error: 

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:226)
at oracle.jdbc.driver.PhysicalConnection.getCharBuffer(PhysicalConnection.java:7672)
at oracle.jdbc.driver.OracleStatement.prepareAccessors(OracleStatement.java:1005)
at oracle.jdbc.driver.OracleStatement.check_row_prefetch_changed(OracleStatement.java:3080)
at oracle.jdbc.driver.OracleResultSetImpl.close_or_fetch_from_next(OracleResultSetImpl.java:321)
at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:277)
at TestJDBC.main(TestJDBC.java:62)


The following is an example based on a trivial query:

Stored procedure:

 

 

 

 

 

 

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms