I've executed a JDBC query to obtain a resultset. Before iterating over it, I'd like to quickly find out how many rows were returned. How can I do this with high performance?

I'm using Java 6, Oracle 11g, and the latest Oracle JDBC drivers.

解决方案

You're going to have to do this as a separate query, for example:

SELECT COUNT(1) FROM table_name

Some JDBC drivers might tell you but this is optional behaviour and, more to the point, the driver may not know yet. This can be due to how the query is optimised eg two example execution strategies in Oracle are to get all rows as quickly as possible or to get the first row as quickly as possible.

If you do two separate queries (one a count and the other the query) then you'll need to do them within the same transaction. This will work well on Oracle but can be problematic on other databases (eg SQL Server will either show you uncommitted data or block on an external uncommitted update depending on your isolation level whereas Oracle supports an isolation level that gives you a transactionally consistent view of the data without blocking on external updates).

Normally though it doesn't really matter how many rows there are. Typically this sort of query is either batch processed or paged and either way you have progress information in the form of rows loaded/processed and you can detect the end of the result set (obviously).

jdbc获取结果行数,如何获取JDBC中的行数?相关推荐

  1. java异步线程数_spring异步service中处理线程数限制详解

    情况简介 spring项目,controller异步调用service的方法,产生大量并发. 具体业务: 前台同时传入大量待翻译的单词,后台业务接收单词,并调用百度翻译接口翻译接收单词并将翻译结果保存 ...

  2. Excel怎样设置标题行,Excel工作表中标题行的处理

    Excel怎样设置标题行,工作表中标题行的处理 Excel做几十.几百行的表格很平常.看下部的数据时看不到表格的标题行,让人搞不清每一列的天文数字究竟代表什么意思.而且正常打印输出时,只有第一页能打印 ...

  3. sql 如何设置行级锁_SQL Server中的行级安全性简介

    sql 如何设置行级锁 In this article, I'm going to discuss Row-Level Security in SQL Server. RLS or Row-Level ...

  4. 国行switch服务器在维护中,国行Switch是否锁区锁服?你关心的问题都将在这里解答...

    国行Nintendo Switch已于今日(12月10日)正式发售,我们已经拿到国行Switch,并对一些备受关注的问题进行了验证,要点如下: • 国行Switch可以玩海外版卡带,海外版游戏也可以正 ...

  5. html拆分单元格多行,拆分一个单元格中多行字符到不同单元格

    有如下格式excel数据: Number           ID                Assignment 1                     A                 ...

  6. css textarea行数_限制textarea中的行数并使用jQuery显示行数

    喵喵时光机 一个非常丑陋但以某种方式起作用的示例指定了textarea行然后在js中   $("textarea").on('keydown keypress keyup',fun ...

  7. php读取文件行读,如何在php中按行读取文件

    您可以使用fgets()函数逐行读取文件: $handle = fopen("inputfile.txt", "r"); if ($handle) { whil ...

  8. mysql查询周数_MySQL:查询中从周数开始的周日期范围

    我有一个数据库表,看起来像这样: | id | clock | info ---------------------------------------------- | 1 | 1262556754 ...

  9. java中获取文件总行数_关于java:如何以有效的方式获取文件中的行数?

    本问题已经有最佳答案,请猛点这里访问. 我有一个大文件. 它包括大约3.000-20.000行. 如何使用Java获取文件中的行总数? 从你的评论到答案来判断,你要找的词是"有效的" ...

  10. 如何在MyEclipse中显示行数

    转载自  如何在MyEclipse中显示行数 如何在MyEclipse中显示行数呢?myeclipse在默认情况下不显示行数时,用户可以自己设置显示行数,行数可以帮助我们方便的查看代码. 首先,打开w ...

最新文章

  1. 基于 HTML5 Canvas 的交互式地铁线路图
  2. 运维基础(15) Linux 应急响应
  3. 【C语言】控制台窗口图形界面编程(六):光标设置
  4. nginx优化-nginx事件处理模型优化use epoll;
  5. 周末包邮送书和小红包中奖名单公布
  6. Java JUC工具类--Master-Worker
  7. 智能机器人语音ic丨智能玩具语音识别芯片丨机器人语音播报芯片丨AI语音提示芯片...
  8. Go语言高性能编程手册(万字长文)
  9. DDC及EDID内容简介
  10. U-boot移植方法
  11. 由IconFont引起的svg、ttf、woff、woff2图标的研究及转换
  12. 解决电脑关机状态下按键盘会开机的问题
  13. vscode快捷键实现快速换行
  14. RLC串联电路的谐振相关参数计算
  15. 如何专注?一个番茄钟就够了!
  16. 生僻字用计算机来,二级office必备,生僻字也可以一体化注音
  17. 大型互联网系统架构演进之路
  18. 对抗中的主动防御 —— HW及小规模网络对抗的战术
  19. CTU Open Contest 2019 计蒜客重现补题报告
  20. 猎头顾问的典型一天——北漂18年(57)

热门文章

  1. 小程序 模糊查询_[轻应用小程序]如何使用信息查询功能?
  2. Flask简介与简单项目操作流程
  3. 网络上总结python中的面试题
  4. 哈工大博士历时半年整理的《Pytorch常用函数函数手册》开放下载!内含200余个函数!...
  5. 技术动态 | 图对比学习的最新进展
  6. 论文浅尝 | Multimodal Few-Shot Learning with Frozen Language Models
  7. 论文浅尝 | AAAI2020 - 多分量图卷积协同过滤方法
  8. transformer 中的注意力机制和胶囊网络中的动态路由:它们在本质上或许具有相似性
  9. Android官方开发文档Training系列课程中文版:分享文件之获取文件信息
  10. PersonGraphDataSet近十万的开放人物关系图谱项目