title: Select Query and will appear to comboBox in Netbeans & mysql
body: <p>I got problem on this code: <br/>
  <code> String charitysql = "SELECT wardName, charityRoomID FROM tbl_charityward,tbl_charityroom2 <br/>WHERE tbl_charityward.charityWardID = tbl_charityroom2.charityWardID";<br/></code></p>
  
  <pre><code> try { 
  
          pst = conn.prepareStatement(charitysql);
          rs = pst.executeQuery();
  
              while (rs.next()) {
                  String wardname = rs.getString("wardName");
                  cb_ward2.addItem(wardname);
                  String roomid = rs.getString("charityRoomID");
                  cb_room2.addItem(roomid);                    
  
              }
  
          }
          catch(Exception e) {
              JOptionPane.showMessageDialog(null, e);
          }
  </code></pre>
  
  <p>this is my tables structure:<br/>
  <code>tbl_charityward<br>
  charityWardID int NOT NULL AUTO_INCREMENT,<br>
  wardName varchar(20),<br>
  status varchar(20),<br>
  PRIMARY KEY (charityWardID)</code></p>
  
  <p><code>tbl_charityRoom2<br>
  charityRoomID INT NOT NULL AUTO_INCREMENT,<br>
  status varchar(20), <br>
  charityWardID int,<br>
  PRIMARY KEY (charityRoomID, charityWardID),<br>
  FOREIGN KEY (charityWardID) REFERENCES tbl_charityward (charityWardID)</code></p>
  
  <p>this is my tables  with values:<br/>
  <code>tbl_charityward<br>
  +-------------+----------+--------+<br>
  |charityWardID| wardName | status |<br>
  +-------------+----------+--------+<br>
  |......1......| Surgical |..Open..|<br>
  |......2......| .Obygine |..Open..|<br>
  |......3......| Pediatric|..Open..|<br>
  +-------------+----------+--------+<br></p>
  
  <p>tbl_charityroom2<br>
  +-------------+--------+-------------+<br>
  |charityRoomID| status |charityWardID|<br>
  +-------------+--------+-------------+<br>
  |......1......|..Open..|......1......|<br>
  |......2......|..Open..|......1......|<br>
  |......3......|..Open..|......2......|<br>
  +-------------+--------+-------------+<br></code></p>
  
  <p>I have 2 comboBox:<br>
  <code>cb_ward2 = which contains wardName<br></code>
  <code>cb_room2 = which contains CharityRoomID</code></p>
  
  <p>If I select a wardName from <code>cb_ward2</code>, then the <code>cb_room2</code> will show the corresponding charityRoomID.</p>
  
  <p>example:<br>
  I select <code>Surgical</code> and the <code>charityRoomID = 1, 2 </code>will appear on <code>cb_room2</code>,<br>
  and when i select <code>Obygine</code>, the <code>charityRoomID = 3 </code>will only appear on <code>cb_room2</code>,<br>
  but when i select <code>Pediatric</code>, no <code>charityRoomID<code> will appear on cb_room2</code></p>
  
  <p>I am using <strong>Netbeans</strong> and <strong>MYSQL</strong></p>
  
  <hr>
  
  <p><strong>EDIT :</strong></p>
  
  <pre>import java.sql.*;&lt;br&gt;
  import javax.swing.*;&lt;br&gt;
  public class addBed extends javax.swing.JFrame {
  
      Connection conn = null;
      ResultSet rs = null;
      PreparedStatement pst = null;
  
      /**
       * Creates new form addBed
       */
      public addBed() {
          initComponents();
      }
  
      void loadcombo() {
  
  
              try {
  
  
              String charitysql = "SELECT wardName, charityRoomID FROM tbl_charityward, tbl_charityroom2 WHERE tbl_charityward.charityWardID = ?";  
              pst = conn.prepareStatement(charitysql);
              pst.setInt(1,tbl_charityroom2.charityWardID);
              rs = pst.executeQuery();
  
                  while (rs.next()) {
  
                      cb_ward2.addItem(rs.getString(1));
  
                      cb_room2.addItem(rs.getString(2));                    
  
                  }
  
              }
              catch(Exception e) {
                  JOptionPane.showMessageDialog(null, e);
              }
  
  
  
  
      }
      private void formWindowOpened(java.awt.event.WindowEvent evt) {                                  
         conn = myconn.ConnectDb();
         loadcombo();
      }                                 
  
      private void btn_add2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  
      }     
  </code></pre>