2012-03-14 6 views
-2

についてImはR用のforループを作成するために探して、[X] Xは全く私にこれに任意の助けを与えるforループありえないためのループのJava/SQL - ループ

構文については、以前に記載されています。

Rがルートの短いので、Xは1,2,3などとすることができるデータベース

の行に対応する、それがR1を選ぶと言う..

だから、言うことが可能です(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

+0

それ以降の計画は今のところこれを行うだけですが、それは後で – user1081326

+0

で解決され、 "r"を定義するコードを表示できますか? –

答えて

0

は、私はあなたが求めるしようとしていると思います質問に対する可能な答えで推測を取る...

R[X]はおそらく、あなたのコレクションのいくつかの並べ替えを与えると仮定すると、あなたが探している可能性があります:

foreach (Route route in R[X]) {

関連する問題