问题:
我从 DB(MySQL)(超过 1 000 000 行)获得大的 ResultSet 并处理每行大约 40 秒。总结,我使用 ResultSet 超过 30 分钟,我得到的记录少于数据库表中实际包含的记录,并且没有错误和警告。如果我计算该 ResultSet 的行数,那没关系(ResultSet 的数量 = DB 的数量)。
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();
}
}
}
创建状态:
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;