Normally when I want to query large result set using Mysql I write this (taken from this answer):
stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
stmt.setFetchSize(Integer.MIN_VALUE);
Now I'm using jOOQ 2.0.5 and I can't achieve the same result.
I've tried calling fetchLazy
with no luck, it loads the entire result set in memory:
Cursor<Record> result = query.fetchLazy(Integer.MIN_VALUE);
As a workaround I can get the sql query using query.getSQL()
and create a suitable Statement
to execute it.
Is there another way to have stream result sets using jOOQ?
According to the JDBC specs, Integer.MIN_VALUE
is not a valid argument for the Statement.setFetchSize()
method:
Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed for ResultSet objects genrated by this Statement. If the value specified is zero, then the hint is ignored. The default value is zero.
Parameters:
rows the number of rows to fetch
Throws:
SQLException - if a database access error occurs, this method is called on a closed Statement or the condition rows >= 0 is not satisfied.
Implementations may throw a SQLException
for negative fetch sizes. Hence, jOOQ doesn't accept parameters less than 0. You should try using a fetch size of 1
instead. In the mean time, the next release of jOOQ might be able to break the JDBC standard, to support this documented MySQL feature
:
https://github.com/jOOQ/jOOQ/issues/1263 (implemented in jOOQ 2.2.0)