ResultSet是否将所有数据加载到内存中或仅在请求时加载? [英] Does a ResultSet load all data into memory or only when requested?

查看:488
本文介绍了ResultSet是否将所有数据加载到内存中或仅在请求时加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.jsp页面,其中有一个GUI表,显示来自Oracle数据库的记录。此表允许典型的分页行为,例如FIRST,NEXT,PREVIOUS和LAST。记录从执行SQL语句时返回的Java ResultSet对象获取。

I have a .jsp page where I have a GUI table that displays records from an Oracle database. This table allows typical pagination behaviour, such as "FIRST", "NEXT", "PREVIOUS" and "LAST". The records are obtained from a Java ResultSet object that is returned from executing a SQL statement.

此ResultSet可能非常大,因此我的问题是:

This ResultSet might be very big, so my question is:

如果我有一个ResultSet包含一百万记录,但是我的表只显示ResultSet中前十个记录的数据,是只有当我开始请求记录数据时才获取数据,或者一旦从执行SQL语句返回ResultSet,所有数据是否被完全加载到内存中?

If I have a ResultSet containing one million records but my table only displays the data from the first ten records in the ResultSet, is the data only fetched when I start requesting record data or does all of the data get loaded into memory entirely once the ResultSet is returned from executing a SQL statement?

推荐答案

Java ResultSet是指向数据库中结果的指针(或光标)。 ResultSet从数据库加载块中的记录。因此,为了回答您的问题,只有在请求时才会抓取数据。

The Java ResultSet is a pointer (or cursor) to the results in the database. The ResultSet loads records in blocks from the database. So to answer your question, the data is only fetched when you request it but in blocks.

如果您需要控制驱动程序一次抓取多少行,您可以使用 setFetchSize()方法。这将允许您控制它一次检索的块的大小。

If you need to control how many rows are fetched at once by the driver, you can use the setFetchSize() method on the ResultSet. This will allow you to control how big the blocks it retrieves at once.

这篇关于ResultSet是否将所有数据加载到内存中或仅在请求时加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆