您的位置:首页 > Web前端

JDBC ResultSet setFetchSize

2010-02-01 18:16 369 查看
Connection conn = null;
ResultSet rs = null;
PreparedStatement stmt = null;
try
{
conn = dbMgr.getConnection();
stmt = conn.prepareStatement(track_sql);
rs = dbMgr.executeQuery(conn, stmt);

while (rs.next())
{
ret.add(rs.getLong(1));
}
} finally
{
if (stmt != null)
stmt.close();
if (rs != null)
rs.close();
if (conn != null)
dbMgr.releaseConnection(conn);
}


When testing in Oracle, above loop is very slow. If add setFetchSize before next, the performance improve significantly

rs.setFetchSize(DbMgr.FETCH_SIZE_LARGE_ROW);


ResultSet interface also provides batch retrieval facility like Statement as mentioned above. It overrides the Statement behaviour.

Initially find the default size by using

ResultSet.getFetchSize(); and then set the size as per requirement

ResultSet.setFetchSize(50);

This feature significantly improves performance when you are dealing with retrieval of large number of rows like search functionality.

TODO: reading full tips

http://www.precisejava.com/javaperf/j2ee/JDBC.htm#JDBC114
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐