通常,当我想使用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


基础教程推荐
- webservice实现springboot项目间接口调用与对象传递示例 2023-03-11
- Go Java算法之从英文中重建数字示例详解 2023-04-06
- Java CompletableFuture实现多线程异步编排 2023-05-13
- java – Hibernate并发插入(MySQL INSERT IGNORE) 2023-10-30
- jsp中变量及方法的声明与使用 2023-08-03
- SpringBoot整合rockerMQ消息队列详解 2023-03-20
- RxJava中map和flatMap的用法区别源码解析 2023-05-24
- 一文掌握Java中的JWT 2022-12-07
- jsp实现textarea中的文字保存换行空格存到数据库的方法 2023-07-30
- jsp输出当前时间的实现代码 2023-08-02