My Oracle Support Banner

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 09, 2023

Applies to:

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


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(
at oracle.jdbc.driver.BufferCache.get(
at oracle.jdbc.driver.PhysicalConnection.getCharBuffer(
at oracle.jdbc.driver.OracleStatement.prepareAccessors(
at oracle.jdbc.driver.OracleStatement.check_row_prefetch_changed(
at oracle.jdbc.driver.OracleResultSetImpl.close_or_fetch_from_next(
at TestJDBC.main(

The following is an example based on a trivial query:

Stored procedure:










To view full details, sign in with your My Oracle Support account.

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

In this Document
 Stored procedure:
 SQL statement:
 Diagnostic Program:
 Example of Memory Heap using Eclipse Memory Analyzer:

My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.