title: How to get all values from database id to jcombobox?
body: <p>I want to get all values from data ID.</p>
  
  <p>I had done the following and just get the first value of ID data. Please help on how to get all values from it.</p>
  
  <pre><code>String sql = "select * from customer";
  Connection cn = null;
  PreparedStatement ps = null;
  Statement st = null;
  ResultSet rs = null;  
  
  public custmanagement() {
      initComponents();        
      setTitle("Customer Management");
      setResizable(false);      
  
      fillcombo();
  }
  
  private void fillcombo() {
      try {            
          cn=DriverManager.getConnection("jdbc:mysql://localhost:3306/dms_db", "root", "");
          ps=cn.prepareStatement(sql);  
  
          rs=ps.executeQuery();
          while (rs.next()) {  
              String id = rs.getString("id");
              cboxid.addItem(id);
          }
  
      } catch (Exception e) {
             JOptionPane.showMessageDialog(null, e);
      }        
  }
  </code></pre>
  
  <p>I already know my problem. It is because I want to retrieve all data when choose id at jcombobox...here is my coding...</p>
  
  <pre><code>private void cboxidActionPerformed(java.awt.event.ActionEvent evt) {                                       
      // TODO add your handling code here:
      String id = cboxid.getSelectedItem().toString();
      try {
          Class.forName("com.mysql.jdbc.Driver");
          cn=DriverManager.getConnection("jdbc:mysql://localhost:3306/dms_db", "root", ""); 
          ps=cn.prepareStatement("select * from customer where id=?");
          ps.setString(1, id);
          rs=ps.executeQuery();
          while (rs.next()) {
              lblname.setText(rs.getString("name"));
              lblic.setText(rs.getString("ic"));
              lbladdress.setText(rs.getString("address"));
              lblgender.setText(rs.getString("gender"));
              lblpackage.setText(rs.getString("package"));
              lblphone.setText(rs.getString("phone"));               
  
  
          }
  
  
      } catch (Exception e) {
          JOptionPane.showMessageDialog(null, e);
      }
  }
  </code></pre>
  
  <p>can someone help me what's wrong with this code...</p>