-1
Connection c = new DataConnection().getDBconnection();
            PreparedStatement p = c.prepareStatement("SELECT bet_Number, SUM(Amount) FROM bet_tbl WHERE bet_Date = ? and status = ? GROUP BY bet_Number");
            p.setString(1, "2013-07-02");
            p.setString(2, "0");
            ResultSet rs = p.executeQuery();
            while (rs.next()) {                
                if(rs.getString(1).equals("01")){lbl01.setText(rs.getString(2));}
                if(rs.getString(1).equals("02")){lbl02.setText(rs.getString(2));}
                if(rs.getString(1).equals("03")){lbl03.setText(rs.getString(2));}
                if(rs.getString(1).equals("04")){lbl04.setText(rs.getString(2));}
                if(rs.getString(1).equals("05")){lbl05.setText(rs.getString(2));}
                if(rs.getString(1).equals("06")){lbl06.setText(rs.getString(2));}
                if(rs.getString(1).equals("07")){lbl07.setText(rs.getString(2));}
                if(rs.getString(1).equals("08")){lbl08.setText(rs.getString(2));}
                if(rs.getString(1).equals("09")){lbl09.setText(rs.getString(2));}
                if(rs.getString(1).equals("10")){lbl10.setText(rs.getString(2));}
                if(rs.getString(1).equals("11")){lbl11.setText(rs.getString(2));}
             }
4

1 に答える 1

1

すべてのデータベース タイプが varchar の場合は、そのように簡単に行うことができます。

JLabel lbl[]=new JLabel[100];
    while (rs.next()) {   
     for(int i=0;i<lbl.length;i++){
       if(rs.getString(1).equals(String.format("%02d",(i+1)))){
         lbl[i].setText(rs.getString(2));
       }
      }
    }
于 2013-07-04T09:39:15.507 に答える