您当前的位置: 首页 > 

qq_34412985

暂无认证

  • 0浏览

    0关注

    1061博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

ResultSet内存溢出OutOfMemory

qq_34412985 发布时间:2020-03-02 22:45:14 ,浏览量:0

 

我用java中的ResultSet从数据库sql查询读取数据,大概有8000行数据左右,但是在将数据从ResultSet中取出并进行处理时,程序卡在第5000行左右不动了 private void generateRptSchemaWithLong(Connection fxqCon, Map 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默认是全部改为获取部分

关注
打赏
1653291990
查看更多评论
立即登录/注册

微信扫码登录

0.0383s