ResultSet内存溢出OutOfMemory

我用java中的ResultSet从数据库sql查询读取数据,大概有8000行数据左右,但是在将数据从ResultSet中取出并进行处理时,程序卡在第5000行左右不动了
private void generateRptSchemaWithLong(Connection fxqCon,
Map<String, TFxqBJHReportSchema> fgsReportMap,
String beginSummaryDate, String summaryDate, String sql, String col)
throws Exception {
PreparedStatement pst = null;
ResultSet rst = null;
String comcodeStr = "";
String fgsCom = "";
TFxqBJHReportSchema rptSchema = null;
String bgDate = beginSummaryDate;
String endDate = summaryDate;

                //组装时间格式
if (!"Bg".equals(col)) {
bgDate = beginSummaryDate.substring(0, 4) + "-"
+ beginSummaryDate.substring(4, 6) + "-"
+ beginSummaryDate.substring(6, 8) + " 00:00:00";
endDate = summaryDate.substring(0, 4) + "-"
+ summaryDate.substring(4, 6) + "-"
+ summaryDate.substring(6, 8) + " 23:59:59";
}
log.info("当前执行的sql语句:" + sql);
try {
pst = proxoolDB.prepareStatement(fxqCon, sql);

pst.setString(1, bgDate);
pst.setString(2, endDate);

rst = pst.executeQuery();
rst.setFetchSize(2000);
while (rst.next()) {//resultset长度大概8000行左右
comcodeStr = rst.getString("comcode");
fgsCom = getAccComcode(fxqCon, comcodeStr);
rptSchema = fgsReportMap.get(fgsCom);
if("Sblg".equals(col)){
log.info("当前更新的机构信息:"+fgsCom);
}
if ("4".equals(rst.getObject("insurednature").toString())) {
log.info("hello 4!");
rptSchema.setMethod(
col + "fzr",
String.valueOf(Long.parseLong(rst.getObject("val").toString())
+ Long.parseLong(rptSchema.getMethod(col
+ "fzr"))));
} else {
log.info("hello others!");//程序在处理到5000行左右时,卡在这个地方不动了,已经卡了一天左右了。
rptSchema.setMethod(
col + "zr",
String.valueOf(Long.parseLong(rst.getObject("val").toString())
+ Long.parseLong(rptSchema.getMethod(col
+ "zr"))));
}
}
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
try {
proxoolDB.release(rst);
proxoolDB.release(pst);
} catch (SQLException e) {
e.printStackTrace();
throw e;
}
}
}

connection手动提交事务,resultset.fetchSize默认是全部改为获取部分

发布了513 篇原创文章 · 获赞 21 · 访问量 15万+

猜你喜欢

转载自blog.csdn.net/qq_34412985/article/details/104622153