问题描述
我有一个 .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:
如果我有一个包含 100 万条记录的 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(int rows) 方法在 ResultSet 上.这将允许您控制它一次检索的块有多大.
If you need to control how many rows are fetched at once by the driver, you can use the setFetchSize(int rows) method on the ResultSet. This will allow you to control how big the blocks it retrieves at once.
这篇关于ResultSet 是将所有数据加载到内存中还是仅在请求时加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!