在我的 java 代码中,我使用 select 语句访问一个 oracle 数据库表。我收到很多行(大约 50.000 行),因此rs.next()需要一些时间来处理所有行。
using ResultSet, the processing of all rows (rs.next) takes about 30 secs
我的目标是加快这个过程,所以我更改了代码,现在使用CachedRowSet:
using CachedRowSet, the processing of all rows takes about 35 secs
我不明白为什么CachedRowSet比正常慢ResultSet,因为CachedRowSet一次检索所有数据,而ResultSet每次rs.next调用时检索数据。
这是代码的一部分:
try {
stmt = masterCon.prepareStatement(sql);
rs = stmt.executeQuery();
CachedRowSet crset = new CachedRowSetImpl();
crset.populate(rs);
while (rs.next()) {
int countStar = iterRs.getInt("COUNT");
...
}
} finally {
//cleanup
}