MySQL流结果集和jOOQ fetchLazy [英] Mysql streaming result set and jOOQ fetchLazy
问题描述
通常,当我想使用Mysql查询大型结果集时,我会这样写(取自此答案):>
stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
stmt.setFetchSize(Integer.MIN_VALUE);
现在我正在使用 jOOQ 2.0.5,但我无法获得相同的结果. /p>
我尝试没有成功地调用fetchLazy
,它将整个结果集加载到内存中:
Cursor<Record> result = query.fetchLazy(Integer.MIN_VALUE);
作为一种解决方法,我可以使用query.getSQL()
获取sql查询并创建合适的Statement
来执行它.
是否还有另一种方法可以使用jOOQ获得流结果集?
根据JDBC规范,对于已记录的MySQL功能 :
https://github.com/jOOQ/jOOQ/issues/1263 (在jOOQ 2.2.0中实现)
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)
这篇关于MySQL流结果集和jOOQ fetchLazy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!