Symptom

When using Mysql with a large set of data an OutOfMemoryError error is raised.

 

Solution

By Default, the MySQL JDBC Driver retrieves all results in memory, which can be the cause of OOM issues when working with large sets of data.

See ResultSet paragraph at http://dev.mysql.com/doc/connector-j/en/connector-j-reference-implementation-notes.html  for further information.

The solution is to indicate to the driver to process the row one by one, like explained in the MySql documentation.

To do that, set the fetch_size to the minimal Integer value. It can be done dynamically with the following rhino expression :

%e(rhino){java.lang.Integer.MIN_VALUE}e(rhino)%