以下是我的代码的一部分。当我运行代码时,执行需要花费太多时间(超过8分钟)。经过几次测试,我发现每个while循环引起的延迟。我试图在循环中移动查询,但这没用。 知道如何减少延迟吗?
sql="update rpttbl set cutsum= ? where temp=?";
prepStmt=conCreate.prepareStatement(sql);
rs=rptStmt.executeQuery("select temp from rpttbl");
prepStmt2=createDBcon.prepareStatement("select sum(la2a) from "+Globals.comp+".sarchivelist where lempid= ? and "
+ "(ldate='"+Globals.year+"-"+Globals.date+"-28') and (la5=22 or la5=33 or la5=2) ");
while(rs.next()){
prepStmt2.setString(1, rs.getString(1));
prepStmt2.execute();
rs2=prepStmt2.getResultSet();
prepStmt.setString(2, rs.getString(1));
if(!rs2.next()){
}
else{
prepStmt.setString(1,rs2.getString(1));
prepStmt.addBatch();
}
prepStmt.executeBatch();
}
sql="update rpttbl set promir= ? where temp=?";
prepStmt=conCreate.prepareStatement(sql);
rs=rptStmt.executeQuery("select temp from rpttbl");
prepStmt2=createDBcon.prepareStatement("select la2a from "+Globals.comp+".sarchivelist where lempid= ? and "
+ "(ldate='"+Globals.year+"-"+Globals.date+"-28') and la6=6 ");
while(rs.next()){
prepStmt2.setString(1, rs.getString(1));
prepStmt2.execute();
rs2=prepStmt2.getResultSet();
prepStmt.setString(2, rs.getString(1));
if(!rs2.next()){
}
else{
prepStmt.setString(1,rs2.getString(1));
prepStmt.addBatch();
}
prepStmt.executeBatch();
}
sql="update rpttbl set proch= ? where temp=?";
prepStmt=conCreate.prepareStatement(sql);
rs=rptStmt.executeQuery("select temp from rpttbl");
prepStmt2=createDBcon.prepareStatement("select sum(la2a) from "+Globals.comp+".sarchivelist where lempid= ? and "
+ "(ldate='"+Globals.year+"-"+Globals.date+"-28') and la6=10001 ");
while(rs.next()){
prepStmt2.setString(1, rs.getString(1));
prepStmt2.execute();
rs2=prepStmt2.getResultSet();
prepStmt.setString(2, rs.getString(1));
if(!rs2.next()){
}
else{
prepStmt.setString(1,rs2.getString(1));
prepStmt.addBatch();
}
prepStmt.executeBatch();
}
编辑: 我移动了prepStmt.executeBatch();在while()循环之外,但这并没有减少延迟。
答案 0 :(得分:0)
执行prepStmt.executeBatch();在while()循环之外