0

在下面的代码中,我将resultset内容复制到arraylist. wile循环的第一部分,即 while(RS.next())返回结果,但是当光标移动到 Next while 循环时,即while(SR.next()) 我得到“结果集已关闭”。请帮助我在哪里做错了。

       String SSQ =   "select DISTINCT S_NUMBER from OTG.S_R_VAL" +

                    "  WHERE R_TS = (SELECT MAX(R_TS) FROM OTG.S_R_VAL) order by S_NUMBER";

              String SDS = "SELECT DISTINCT S_NUMBER FROM OTG.S_R_VAL AS STG WHERE S_NUMBER NOT IN" +

                            "(SELECT S_NO FROM OTG.R_VAL AS REV WHERE STG.S_NUMBER = REV.S_NO )";

              String SSR = "SELECT DISTINCT S_NO FROM OTG.R_VAL where S_NO != 'NULL' order by S_NO";

              String SSO =  "Select O_UID from OTG.OPTY where C_S_NO IN" +

             "( SELECT DISTINCT S_NUMBER FROM OTG.S_R_VAL AS STG WHERE S_NUMBER NOT IN(SELECT S_NO FROM OTG.R_VAL AS REV WHERE STG.S_NUMBER = REV.S_NO ))";

              //Statement statement;

            try {

         connection = DatabaseConnection.getCon();

         statement = connection.createStatement();

         statement1 = connection.createStatement();

         statement2 = connection.createStatement();

         statement3 = connection.createStatement();

         statement4 = connection.createStatement();



      ResultSet RS = statement1.executeQuery(selectQuery);

      ResultSet DS = statement2.executeQuery(Distinct_SiebelNo);

      ResultSet SR = statement3.executeQuery(SiebelNo_Rev);

      ResultSet SO = statement4.executeQuery(selected_OppId);




      ArrayList<String> RSList = new ArrayList<String>(); 

      ArrayList<String> SRList = new ArrayList<String>();

     /* ResultSetMetaData resultSetMetaData = RS.getMetaData();

      int count = resultSetMetaData.getColumnCount();*/

     int count=1;

      System.out.println("******count********"+count); 

      while(RS.next()) {

          int i = 1;

          count=1;

          while(i < count) 

                      {

              RSList.add(RS.getString(i++));

                  }

          System.out.println(RS.getString("SIEBEL_NUMBER"));


          RSList.add(  RS.getString("SIEBEL_NUMBER"));


        }

    /*  ResultSetMetaData resultSetMetaData1 = SR.getMetaData();

      int count1 = resultSetMetaData1.getColumnCount();*/

      int count1=1;

      while(SR.next()) {

          int i = 1;

          while(i < count1) 

                      {

              SRList.add(SR.getString(i++));

                  }

          System.out.println(SR.getString("SIEBEL_NO"));

          SRList.add(  SR.getString("SIEBEL_NO"));


        }SR.close();

    connection.commit();


} catch (SQLException e) {

        // TODO Auto-generated catch block

        e.printStackTrace();

    }
  }
}
}
4

2 回答 2

0

RS您在第二个循环(System.out.println行)中使用第一个结果集( )

于 2013-08-27T09:39:21.140 回答
0

每个循环的逻辑都是有缺陷的。

  int count=1;//Count is being set to one
  while(RS.next()) {
      int i = 1;//i is being set to one
      count=1;//count again set to one
      while(i < count) //condition will always fail as one is never less than one
      {
          RSList.add(RS.getString(i++));//Code is never Reached

      }
      System.out.println(RS.getString("SIEBEL_NUMBER"));


      RSList.add(  RS.getString("SIEBEL_NUMBER"));


    }

第二个 while 不需要。只需使用这个:

   int count = 1;
   while(RS.next()) {
      RSList.add(RS.getString(count++));
      System.out.println(RS.getString("SIEBEL_NUMBER"));
      RSList.add(  RS.getString("SIEBEL_NUMBER"));
    }

编辑

   int count1=1;
   while(SR.next()) {
      SRList.add(SR.getString(count1++));
      System.out.println(SR.getString("SIEBEL_NO"));
      SRList.add(  SR.getString("SIEBEL_NO"));
   }

编辑2:

for (String s : RSList)
   for(String s1 : SRList)
      if (s.equals(s1))
         //Do what you need
于 2013-08-27T09:46:36.673 回答