通常,当我想使用Mysql查询大型结果集时,我写这个(取自this answer):stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);stmt.setFetchSize(Integer.MIN_VA...
通常,当我想使用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
- 从零开始讲解Java微信公众号消息推送实现 2023-06-01
- Java中HashMap如何解决哈希冲突 2022-11-16
- MyBatis-Plus实现条件查询的三种格式例举详解 2023-04-17
- Springboot JPA如何使用distinct返回对象 2022-10-24
- Java实现简单画画画板 2022-12-16
- Java数据结构之加权无向图的设计实现 2023-07-01
- Springboot使用SPI注册bean到spring容器的示例代码 2023-06-10
- Java实现订单超时未支付自动取消的8种方法总结 2023-04-18
- mybatisplus isNotNull不生效问题及解决 2023-01-24
- Spring @Component自定义注解实现详解 2023-05-14