gpt4 book ai didi

java - Mysql流式结果集和jOOQ fetchLazy

转载 作者:可可西里 更新时间:2023-11-01 07:33:24 28 4
gpt4 key购买 nike

通常,当我想使用 Mysql 查询大型结果集时,我会这样写(取自 this answer):

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

现在我正在使用 jOOQ 2.0.5,我无法获得相同的结果。

我试过调用 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 中实现)

关于java - Mysql流式结果集和jOOQ fetchLazy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9949750/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com