当前位置: 首页 > 知识库问答 >
问题:

为什么我得到列表中每个值的多次迭代[重复]

米夕
2023-03-14

我有一个应用程序,我正在做一些数据库操作。根据这些价值,我也在做一些计算。但是我得到了列表中每个值的多次迭代

for(int i=0;i<consultantMailList.size();i++){

             String consultantRatio = " select count(distinct CANDYS.candidateId) from "
                     +" (Select C.candidateID,J.joborderID from db_candidatenote C, db_jobordernote J " 
                     +" where C.noteid=J.noteid and C.action like 'Engaged' " 
                     +" and C.dateadded between "+ "\""+ new java.sql.Timestamp(startDate.getTime())+ "\" and "+ "\""+ new java.sql.Timestamp(endDate.getTime())+ "\"  ) N,"
                     +" (Select distinct Note.candidateId, JNote.jobOrderID " 
                     +" from db_candidatenote Note,db_jobordernote JNote, corporateuser User where " 
                     +" Note.noteid=JNote.noteid "
                     +" and Note.commentingPersonID = User.userid " 
                     +" and User.name= "+"\""+consultantNameList.get(i)+"\""
                     +" and Note.action='Sourcing') CANDYS "
                     +" where N.candidateID= CANDYS.candidateId "
                     +" and N.joborderid=CANDYS.jobOrderID "                

                     +" union"

                     +" select count(distinct CANDYS.candidateId) from "
                     +" (Select C.candidateID,J.joborderID from db_candidatenote C, db_jobordernote J " 
                     +" where C.noteid=J.noteid and C.action like 'Qualification' " 
                     +" and C.dateadded between "+ "\""+ new java.sql.Timestamp(startDate.getTime())+ "\" and "+ "\""+ new java.sql.Timestamp(endDate.getTime())+ "\"  ) N,"
                     +" (Select distinct Note.candidateId, JNote.jobOrderID " 
                     +" from db_candidatenote Note,db_jobordernote JNote, corporateuser User where " 
                     +" Note.noteid=JNote.noteid "
                     +" and Note.commentingPersonID = User.userid " 
                     +" and User.name= "+"\""+consultantNameList.get(i)+"\""
                     +" and Note.action='Sourcing') CANDYS "
                     +" where N.candidateID= CANDYS.candidateId "
                     +" and N.joborderid=CANDYS.jobOrderID "

                     +" union "

                     +" select count(distinct CANDYS.candidateId) from "
                     +" (Select C.candidateID,J.joborderID from db_candidatenote C, db_jobordernote J " 
                     +" where C.noteid=J.noteid and C.action like 'Internal Submission' "
                     +" and C.dateadded between "+ "\""+ new java.sql.Timestamp(startDate.getTime())+ "\" and "+ "\""+ new java.sql.Timestamp(endDate.getTime())+ "\"  ) N,"
                     +" (Select distinct Note.candidateId, JNote.jobOrderID " 
                     +" from db_candidatenote Note,db_jobordernote JNote, corporateuser User where " 
                     +" Note.noteid=JNote.noteid "
                     +" and Note.commentingPersonID = User.userid " 
                     +" and User.name= "+"\""+consultantNameList.get(i)+"\""
                     +" and Note.action='Sourcing') CANDYS "
                     +" where N.candidateID= CANDYS.candidateId "
                     +" and N.joborderid=CANDYS.jobOrderID "

                     +" union "

                    +" select count(distinct CANDYS.candidateId) from sendout S,"
                    +" (Select distinct Note.candidateId, JNote.jobOrderID " 
                    +" from db_candidatenote Note,db_jobordernote JNote, corporateuser User where " 
                    +" Note.noteid=JNote.noteid "
                    +" and Note.commentingPersonID = User.userid " 
                    +" and User.name= "+"\""+consultantNameList.get(i)+"\""
                    +" and Note.action='Sourcing' ) CANDYS "
                    +" where S.candidateID= CANDYS.candidateId "
                    +" and S.joborderid=CANDYS.jobOrderID "
                    +" and S.dateadded between "+ "\""+ new java.sql.Timestamp(startDate.getTime())+ "\" and "+ "\""+ new java.sql.Timestamp(endDate.getTime())+ "\" "

                    +" union"

                    +"  select count(distinct CANDYS.candidateId) from "
                    +"  (Select C.candidateID,J.joborderID from db_candidatenote C, db_jobordernote J " 
                    +"  where C.noteid=J.noteid and C.action like '%Interview%' " 
                    +"  and C.dateadded between "+ "\""+ new java.sql.Timestamp(startDate.getTime())+ "\" and "+ "\""+ new java.sql.Timestamp(endDate.getTime())+ "\"  ) N,"
                    +"  (Select distinct Note.candidateId, JNote.jobOrderID " 
                    +"  from db_candidatenote Note,db_jobordernote JNote, corporateuser User where " 
                    +"  Note.noteid=JNote.noteid "
                    +"  and Note.commentingPersonID = User.userid " 
                    +"  and User.name= "+"\""+consultantNameList.get(i)+"\""
                    +"  and Note.action='Sourcing') CANDYS "
                    +"  where N.candidateID= CANDYS.candidateId "
                    +"  and N.joborderid=CANDYS.jobOrderID "

                    +"  union "

                    +"  select count(distinct CANDYS.candidateId ) from placement P,(Select distinct Note.candidateId, JNote.jobOrderID " 
                    +"  from db_candidatenote Note,db_jobordernote JNote, corporateuser User where " 
                    +"  Note.noteid=JNote.noteid "
                    +"  and Note.commentingPersonID = User.userid " 
                    +"  and User.name= "+"\""+consultantNameList.get(i)+"\""
                    +"  and Note.action='Sourcing') CANDYS "
                    +"  where P.candidateID= CANDYS.candidateId "
                    +"  and P.joborderid=CANDYS.jobOrderID "
                    +"  and P.dateadded between "+ "\""+ new java.sql.Timestamp(startDate.getTime())+ "\" and "+ "\""+ new java.sql.Timestamp(endDate.getTime())+ "\" " ;


                     String countAnalystPlacement ="SELECT COUNT(*) FROM placement where analyst like "+"\""+consultantNameList.get(i)+"\" and dateAdded between "+ "\""+ new java.sql.Timestamp(startDate.getTime())+ "\" and "+ "\""+ new java.sql.Timestamp(endDate.getTime())+ "\"" ;

                     rsServeResource7 = st.executeQuery(countAnalystPlacement);
                      while(rsServeResource7.next()){
                          placementActual = rsServeResource7.getInt(1);
                      }

                      System.out.println("Placement Actual for :"+consultantNameList.get(i)+"--"+placementActual);

                    //System.out.println(consultantRatio);
                    rsServeResource2 = st.executeQuery(consultantRatio);            
                    while (rsServeResource2.next()) {                           

                    // these variables will be divided by actual milestone numbers like source to engage / engage etc within that time range ..

                    if(rsServeResource2.getString(1)!=null){
                    sourceToEngage = Integer.parseInt(rsServeResource2.getString(1));
                    }else if(rsServeResource2.getString(2)!=null){
                    sourceToQualification = Integer.parseInt(rsServeResource2.getString(2));
                    }else if(rsServeResource2.getString(3)!=null){
                    sourceToIs = Integer.parseInt(rsServeResource2.getString(3));
                    }else  if(rsServeResource2.getString(4)!=null){
                    sourceToPresent = Integer.parseInt(rsServeResource2.getString(4));
                    }else if(rsServeResource2.getString(5)!=null){
                    sourceToInterview = Integer.parseInt(rsServeResource2.getString(5));
                    }else if(rsServeResource2.getString(6)!=null){
                    sourceToPlacament = Integer.parseInt(rsServeResource2.getString(6));
                }


                System.out.println("Source to engage for :"+consultantNameList.get(i)+"-->"+sourceToEngage);
                System.out.println("Source to qualification for :"+consultantNameList.get(i)+"-->"+sourceToQualification);  
                System.out.println("Source to IS for :"+consultantNameList.get(i)+"-->"+sourceToIs);    
                System.out.println("Source to Present for :"+consultantNameList.get(i)+"-->"+sourceToPresent);  
                System.out.println("Source to interview for :"+consultantNameList.get(i)+"-->"+sourceToInterview);  
                System.out.println("Source to placement for :"+consultantNameList.get(i)+"-->"+sourceToPlacament);  



                String sourcingSql = "select count(distinct candidateId) from db_candidatenote Note,corporateuser User where  Note.commentingPersonID =User.userid and User.name like "+"\""+consultantNameList.get(i)+"\" and  action IN ('Sourcing','Sourcing-Green') and Note.dateAdded between "+ "\""+ new java.sql.Timestamp(startDate.getTime())+ "\" and "+ "\""+ new java.sql.Timestamp(endDate.getTime())+ "\"" ;
                rsServeResource6 = st.executeQuery(sourcingSql);
                    while(rsServeResource6.next()){

                        if(rsServeResource6.getString(1)!=null){                                
                            sourcingActual = Integer.parseInt(rsServeResource6.getString(1));                           
                        } 
                    }
                System.out.println("Actual number of Sourcing :"+sourcingActual);

         /******************    value modification done here *********************************/
                    if(sourceToEngage!=0){
                        sourceToEngage = sourcingActual/sourceToEngage;
                    }if(sourceToQualification !=0){
                        sourceToQualification =sourcingActual/qualificationActual;
                    }if(isSubmissionActual !=0){
                        sourceToIs = sourcingActual / isSubmissionActual;
                    }if(presentActual !=0){
                        sourceToPresent = sourcingActual /presentActual;
                    }if(interviewedActual !=0){
                        sourceToInterview = sourcingActual/interviewedActual;
                    }if(placementActual !=0){
                        sourceToPlacament =  sourcingActual/placementActual;
                    }
            /*********************************** Ends Here ************************************/        
                    System.out.println("sourceToEngageRatio" +sourceToEngage);
                    System.out.println("sourceToQualificationRatio" +sourceToQualification);
                    System.out.println("sourceToIsRatio" +sourceToIs);
                    System.out.println("sourceToPresentRatio" +sourceToPresent);
                    System.out.println("sourceToInterviewRatio" +sourceToInterview);
                    System.out.println("sourceToPlacementRatio" +sourceToPlacament);

                }       

                    if(rsServeResource2.getRow() % 2==0){
                        analystRatioTable = analystRatioTable + "<tr style=\"border-bottom: 2px solid #b6b6b4;\"><td style=\"color: #1391d7;\">"+consultantNameList.get(i)+"</td><td>"+sourceToEngage+":"+"1"+"</td><td>"+sourceToQualification+":"+"1"+"</td><td>"+"</td><td>"+sourceToIs+":"+"1"+"</td><td>"+sourceToPresent+":"+"1"+"</td><td>"+sourceToInterview+":"+"1"+"</td><td>"+sourceToPlacament+":"+"1"+"</td></tr>";
                    } else {
                        analystRatioTable = analystRatioTable + "<tr style=\"border-bottom: 2px solid #b6b6b4;\"><td style=\"color: #1391d7;\">"+consultantNameList.get(i)+"</td><td>"+sourceToEngage+":"+"1"+"</td><td>"+sourceToQualification+":"+"1"+"</td><td>"+"</td><td>"+sourceToIs+":"+"1"+"</td><td>"+sourceToPresent+":"+"1"+"</td><td>"+sourceToInterview+":"+"1"+"</td><td>"+sourceToPlacament+":"+"1"+"</td></tr>";
                    }

                    System.out.println("Table data created :"+analystRatioTable);

                 }           

我得到多个时间每个值为什么是这样。列表大小为5

这是我的代码,我在排队时得到了那个例外

但我不明白我错在哪里。谁来帮忙

共有1个答案

欧阳高昂
2023-03-14

您声称获得异常的代码确实出现在上面更大的代码中。

然而,我在别处看到了一个问题:

if(rsServeResource2.getRow() % 2==0)

在执行不同的查询并获得新的结果集-rsServeResource6-这意味着rsServeResource2已关闭且无法访问后,您可以访问rsServeResource2结果集。

编辑:

这不是唯一的问题。错误的缩进使得很难注意到rsServeResource6=st.executeQuery(Source cingSql);在迭代上一个结果集的循环中。这将导致关闭rsServeResource2。如果必须同时迭代两个结果集,请使用不同的语句对象来执行它们。

 类似资料:
  • 我试图创建一个列表k,其中包含的所有元素,除了那些索引位于中的元素。我做错了什么?错误是:

  • 问题内容: 我有一个像(669256.02,6117662.09,669258.61,6117664.39,669258.05,6117665.08)的集合需要迭代 将打印 我在Python 3.3 btw上 问题答案: 您可以使用迭代器:

  • 考虑这个简单的C++函数来计算数组的前缀和: 它是4个融合的UOP1,这个CPU可以支持4个融合的OPs/周期。 有通过和携带的依赖链,每个都是一个循环,但是这些UOP可以到4个ALU端口中的任何一个,所以似乎不太可能冲突。融合的需要转到p6,这是一个更令人担忧的问题,但我只测量到p6的1.1 UOPS/迭代。这将解释每次迭代1.1个循环,但不是1.4个循环。如果我将循环展开2倍,端口压力会低得多

  • 问题内容: 这是我的内容: 在Jenkins中使用Pipeline插件执行作业时,仅打印列表中的第一项。 有人可以向我解释这种奇怪的行为吗?是虫子吗?还是只是我不了解Groovy语法? 编辑 :预期的作品: 问题答案: 此处接受的答案指出这是一个已知的错误,并且使用了对我不起作用的解决方法,因此,我将提供我最近发现的更新。 尽管有了JENKINS-26481的解决方案(在撰写本文时,它还算是最近的

  • 问题内容: 我希望有人能提供帮助。但是,每当我运行我的代码并尝试查看所有代码时,我都回到列表框中。 谁能看到原因? 码: 问题答案: 即使设置了列表框的和,我也总是要处理此问题。 您当前的代码正确无误,并且可以正常工作,如果您需要访问任意列的当前选定项目值,则可以让他们这样做: 我希望获得完整的结果是,如果您有更多的列,您仍然可以访问它们的值并对其进行任何操作。

  • 我想知道为什么列表理解比附加在列表上要快得多。我以为区别只是表达,但事实并非如此。 列表理解速度提高了50%。为什么?