【发布时间】:2011-10-06 10:04:32
【问题描述】:
在我的 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
}
【问题讨论】:
标签: java oracle cachedrowset