通常,当我想使用MySQL查询大型结果集时,我写这个(取自this answer):
stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
stmt.setFetchSize(Integer.MIN_VALUE);
我试过没有运气调用fetchLazy,它将整个结果集加载到内存中:
Cursor<Record> result = query.fetchLazy(Integer.MIN_VALUE);
作为一种解决方法,我可以使用query.getsql()获取SQL查询,并创建一个合适的Statement来执行它.
有没有其他方法可以使用jOOQ获得流结果集?
解决方法:
根据JDBC规范,Integer.MIN_VALUE不是Statement.setFetchSize()
方法的有效参数:
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.
实现可能会为负提取大小抛出sqlException.因此,jOOQ不接受小于0的参数.您应该尝试使用1的提取大小.与此同时,jOOQ的下一个版本可能会破坏JDBC标准,以支持这一documented MySQL feature
:
https://github.com/jOOQ/jOOQ/issues/1263(在jOOQ 2.2.0中实现)