title: executing code taking too much time
body: <p>Below is a part of my code.When I run the code it takes too much time to be executed (more than 8 minutes). After few tests, I found out that delay caused by each while loop. I tried to move the queries inside the loop but that was useless.
  Any idea how I can reduce the delay?</p>
  
  <pre><code>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();
              }
  </code></pre>
  
  <p>edit:
  I moved prepStmt.executeBatch(); outside the while() loop, but that didn't reduce the delay.</p>