在我的java代码中,我使用select语句访问oracle数据库表。 我收到很多行(约50.000行),所以rs.next()
需要一些时间来处理所有行。CachedRowSet比ResultSet慢吗?
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
}
即使CachedRowSet同时检索所有数据,也需要时间返回该数据 - 原始SQL查询从Oracle控制台上独立运行多久? –