2012-03-14 68 views
-2

即時通訊尋求建立一個for循環的R [X] X是在前面的for循環的Java/SQL - For循環

的語法for循環心不是給我任何幫助,這都說明。

r是一個短路線,說它挑選R1,將對應於一個行中的數據庫

所以X可以是1,2,3等。

那麼,是否可以說對於(R [X])?

CODE:

for(int X = 1; X < records; X++) { 

       for(r[X]) { 

      //<editor-fold defaultstate="collapsed" desc="To check if RX is in Collision Table"> 
      try { 
       Class.forName("oracle.jdbc.driver.OracleDriver"); 
       //load the oracle driver...needs to be in classes folder in jre folder 
      } catch (ClassNotFoundException e) { 
       System.out.println(
         " Can't find class oracle.jdbc.driver.OracleDriver"); 
       System.exit(1); 
      } 

      Connection conn5 = null; 
      //new connection object 
      Statement stmtFindRx = null; 
      //new statemnt object 
      ResultSet checkRx = null; 
      //new record set object 
      try { 
       conn5 = DriverManager.getConnection("jdbc:oracle:thin:@oracle.staff.ittralee.ie:1521:orcl", 
         "*", "*"); 
       stmtFindRx = conn5.createStatement(); 
       // create the statement for this connection 
       //</editor-fold> 

        checkRx = stmtFindRx.executeQuery(
        "*********"); 
        // get the results of select query and store in recordset object 


        while (checkRx.next()) { 
        // move to first/next record of recordset 
        JOptionPane.showMessageDialog(null, " the answer is " + checkRx.getString(1)); 
        //JOptionPane.showMessageDialog(null, " the answer is " + fRoutes); 
        // output next record using string format 
       } 

       //<editor-fold defaultstate="collapsed" desc="Error handling for Select Statement"> 
       checkRx.close(); 
       checkRx = null; 
       stmtFindRx.close(); 
       stmtFindRx = null; 
       conn5.close(); 
       conn5 = null; 

      } catch (SQLException e) { 
       System.out.println(" A SQL error: " + e.getMessage()); 

      } finally { 
       if (checkRx != null) { 
        try { 
         checkRx.close(); 
        } catch (SQLException ignore) { 
        } 
       } 

       if (stmtFindRx != null) { 
        try { 
         stmtFindRx.close(); 
        } catch (SQLException ignore) { 
        } 
       } 

       if (conn5 != null) { 
        try { 
         conn5.close(); 
        } catch (SQLException ignore) { 
        } 
       } 
      } 

      // </editor-fold> 


       } 

      } 
+2

不要加載驅動程序或建立在迴路中DB連接。做一次並重新使用連接,或使用連接池。 – Stefan 2012-03-14 14:51:57

+0

這就是我現在正在做這個計劃,它將在稍後解決 – user1081326 2012-03-14 14:53:26

+0

你能顯示定義「r」的代碼嗎? – 2012-03-14 14:57:51

回答

0

隔空猜測可能的答案的問題,我認爲你要問...

假設R[X]會給你某種集合,也許你可能會尋找:

foreach (Route route in R[X]) {