resultSet.next() 做什么
What does resultSet.next() do
我有一个简单的问题。如果我的过程返回 500 行,那么在第 1 行我的结果集有 500 行。这意味着现在所有记录都存在于该结果集对象中。我说得对吗?
如果 rs.next 迭代需要时间,这意味着它与存储过程性能无关,因为我们已经在 Java 端获得了包含所有 500 条记录的结果集对象。我说得对吗?
rs = (ResultSet)callableStatement.getObject(1);
logger.debug("Iterating ResultSet Starts");
Bean bean = null;
while(rs.next()) {
logger.debug(“some logic but commented to check performance”);
}
This means now all the records are present in this resultset object. am i correct ?
通常这是不正确的。 ResultSet
通常是对数据库游标的抽象,它会在 next
被调用时按需获取结果集的记录。
只有在某些特殊情况下,您才会得到所谓的"client-side cursor",这意味着所有数据都已提前复制到您的身边。这是一种不受欢迎的行为,是 JDBC 规范要求数据库本身不支持的某些情况的解决方法。
CallableStatement 和 ResultSet 都有一个提取大小,它决定了在遍历结果集时一次从游标中检索多少行。默认情况下,您不会获取全部 500 行,您获取的行数最多为驱动程序的提取大小。根据 this Oracle JDBC documentation Oracle 的默认提取大小要低很多:
By default, when Oracle JDBC executes a query, it receives the result set 10 rows at a time from the database cursor. This is the default Oracle row-prefetch value. You can change the number of rows retrieved with each trip to the database cursor by changing the row-prefetch value (see "Oracle Row Prefetching" for more information).
JDBC 2.0 also allows you to specify the number of rows fetched with each database round trip for a query, and this number is referred to as the fetch size. In Oracle JDBC, the row-prefetch value is used as the default fetch size in a statement object. Setting the fetch size overrides the row-prefetch setting and affects subsequent queries executed through that statement object.
Fetch size is also used in a result set. When the statement object executes a query, the fetch size of the statement object is passed to the result set object produced by the query. However, you can also set the fetch size in the result set object to override the statement fetch size that was passed to it. (Also note that changes made to a statement object's fetch size after a result set is produced will have no affect on that result set.)
使用默认设置 10,您的代码将进行 50 次往返以从过程调用中获取所有数据。 (这个文档很旧——它谈论 JDBC 2.0 就好像它是新的一样——所以它可能已经过时了,你应该检查你的获取大小设置为什么。)按顺序更改获取大小一次取回所有行应该最大限度地减少跨网络传输的开销。
我有一个简单的问题。如果我的过程返回 500 行,那么在第 1 行我的结果集有 500 行。这意味着现在所有记录都存在于该结果集对象中。我说得对吗?
如果 rs.next 迭代需要时间,这意味着它与存储过程性能无关,因为我们已经在 Java 端获得了包含所有 500 条记录的结果集对象。我说得对吗?
rs = (ResultSet)callableStatement.getObject(1);
logger.debug("Iterating ResultSet Starts");
Bean bean = null;
while(rs.next()) {
logger.debug(“some logic but commented to check performance”);
}
This means now all the records are present in this resultset object. am i correct ?
通常这是不正确的。 ResultSet
通常是对数据库游标的抽象,它会在 next
被调用时按需获取结果集的记录。
只有在某些特殊情况下,您才会得到所谓的"client-side cursor",这意味着所有数据都已提前复制到您的身边。这是一种不受欢迎的行为,是 JDBC 规范要求数据库本身不支持的某些情况的解决方法。
CallableStatement 和 ResultSet 都有一个提取大小,它决定了在遍历结果集时一次从游标中检索多少行。默认情况下,您不会获取全部 500 行,您获取的行数最多为驱动程序的提取大小。根据 this Oracle JDBC documentation Oracle 的默认提取大小要低很多:
By default, when Oracle JDBC executes a query, it receives the result set 10 rows at a time from the database cursor. This is the default Oracle row-prefetch value. You can change the number of rows retrieved with each trip to the database cursor by changing the row-prefetch value (see "Oracle Row Prefetching" for more information).
JDBC 2.0 also allows you to specify the number of rows fetched with each database round trip for a query, and this number is referred to as the fetch size. In Oracle JDBC, the row-prefetch value is used as the default fetch size in a statement object. Setting the fetch size overrides the row-prefetch setting and affects subsequent queries executed through that statement object.
Fetch size is also used in a result set. When the statement object executes a query, the fetch size of the statement object is passed to the result set object produced by the query. However, you can also set the fetch size in the result set object to override the statement fetch size that was passed to it. (Also note that changes made to a statement object's fetch size after a result set is produced will have no affect on that result set.)
使用默认设置 10,您的代码将进行 50 次往返以从过程调用中获取所有数据。 (这个文档很旧——它谈论 JDBC 2.0 就好像它是新的一样——所以它可能已经过时了,你应该检查你的获取大小设置为什么。)按顺序更改获取大小一次取回所有行应该最大限度地减少跨网络传输的开销。