当前位置:   article > 正文

java中什么是结果集,在Java中使用结果集的有效方法

java大结果集经常出现的场景及规避

您可以使用setFetchSize(rows)来优化提取大小,该提取大小从DB中一次获取指定的行数。

conn = getDbConnection();

Statement createStatement = conn.createStatement();

createStatement.setFetchSize(1000);

ResultSet rs = createStatement.executeQuery(“Select * from myTable”);

while (rs.next())

{

//do nothing

}请注意,fetchSize只是对DB的提示,它可能会忽略该值。只有测试才能揭示它是否是最佳的。

此外,在您的情况下,最好更改Statement的Scrollable属性,因为您可能不会立即处理所有记录。选择哪个可滚动选项取决于您是否要在迭代时查看其他更改。

//TYPE_FORWARD_ONLY

// The constant indicating the type for a ResultSet object

// whose cursor may move only forward.

conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,

ResultSet.CONCUR_READ_ONLY);要么

//TYPE_SCROLL_INSENSITIVE

// The constant indicating the type for a ResultSet object that is

// scrollable but generally not sensitive to changes made by others.

conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_READ_ONLY);要么

//TYPE_SCROLL_SENSITIVE

// The constant indicating the type for a ResultSet object that is

// scrollable and generally sensitive to changes made by others.

conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,

ResultSet.CONCUR_READ_ONLY);有关详细信息,请参阅JDBC API Guide

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/422359
推荐阅读
相关标签
  

闽ICP备14008679号