Search code examples
javamysqljdbcc3p0

Setting fetch size to negative number


I'm working with someone else's code, which contains the lines:

Connection conn = dataSource.getConnection();
conn.setAutoCommit(false);

Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
stmt.setFetchSize(Integer.MIN_VALUE);

ResultSet rs = stmt.executeQuery(myQuery);

I was wondering if someone could explain the effect of setting the fetch size to Integer.MIN_VALUE? That is, does it fetch the maximum number of rows possible to memory, or does it behave otherwise?

I should mention that our data source is a C3P0 connection pool, which uses the MySQL JDBC driver.


Solution

  • From the docs (which explicitly show the two createStatement/setFetchSize lines in an example code snippet):

    The combination of a forward-only, read-only result set, with a fetch size of Integer.MIN_VALUE serves as a signal to the driver to stream result sets row-by-row.

    In the spirit of teaching to fish, my google search was "mysql fetch size jdbc".