JDBC ResultSet setFetchSize

 

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

 

 

你可能感兴趣的:(java)