jdon 的分頁機制的效率低,

smallyi發表於2007-04-23
c = dataSource.getConnection();

DbUtil.testConnection(c);
ps = c.prepareStatement(qcdk.getSqlquery(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

jdbcUtil.setQueryParams(qcdk.getQueryParams(), ps);

rs = ps.executeQuery();
if (DbUtil.supportsFetchSize)
rs.setFetchSize(blockSize);
// Many JDBC drivers don't implement scrollable cursors the real
// way, but instead load all results into memory. Looping through
// the results ourselves is more efficient.
for (int i = 0; i < blockStart; i++) {
if (!rs.next()) break;
}
blockSize ++;
while(rs.next() && (--blockSize > 0)) {
Object result = rs.getObject(1);
logger.debug("[JdonFramework]--> found a primary key = " + result + ", type:" + result.getClass().getName());
items.add(result);
}

logger.debug("[JdonFramework]--> get a result succefully ..");

一次取出所有的記錄,然後遍歷記憶體取

相關文章