我從DB(MySQL)(超過1 000 000行)獲取大的ResultSet並處理每行約40秒。 總結,我使用ResultSet超過30分鐘,我得到的記錄比數據庫表中真正包含的少,並且沒有錯誤也沒有任何warn。如果我計算該ResultSet的行數量,它是好的(ResultSet的數量=數據庫的數量)。
mysql服務器或mysql jdbc驅動程序或其他的一些限制?
我的代碼。它工作在Spring框架:
public void query(String query, RowCallbackHandler rowCallbackHandler) throws SQLException {
ResultSet rs = null;
ResultSet rsCount = null;
Statement stmt = null;
Statement stmtCount = null;
try {
stmt = createStatmant();
rs = stmt.executeQuery(query);
if (rs == null) {
log.info("result set is null");
}
stmtCount = createStatmant();
rsCount = stmtCount.executeQuery(query);
int i = 0;
while(rsCount.next()){
i++;
}
log.info("ResultSet size : "+i);
int j = 0;
rs.next();
do{
j++;
rowCallbackHandler.processRow(rs);
}while (rs.next());
log.info("ResultSet size real : "+i);
log.info("ResultSet size fact : "+j);
} catch (SQLException e) {
throw new RuntimeException(e.getMessage());
}finally{
if(stmt!=null){
stmt.close();
}
if(rs!=null){
rs.close();
}
if(rsCount!=null){
rsCount.close();
}
}
}
createStatment:
private Statement createStatmant() throws SQLException {
((BasicDataSource)dataSource).setTimeBetweenEvictionRunsMillis(1000*60*60);
Statement stmt = dataSource.getConnection().createStatement(
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
stmt.setFetchSize(fetchSize);
stmt.setMaxRows(50000000-1);
return stmt;
}
數據源是類全局變量:
private javax.sql.DataSource dataSource;
請粘貼您的代碼,以便其輕鬆識別問題。 – 2013-03-20 07:11:58
它看起來像你的代碼中的問題。 – 2013-03-20 07:12:03