Java 如何获取从数据库id到jcombobox的所有值?

Java 如何获取从数据库id到jcombobox的所有值?,java,mysql,database,user-interface,netbeans,Java,Mysql,Database,User Interface,Netbeans,我想从数据ID中获取所有值 我完成了以下操作,只得到了ID数据的第一个值。请帮助了解如何从中获取所有值 String sql = "select * from customer"; Connection cn = null; PreparedStatement ps = null; Statement st = null; ResultSet rs = null; public custmanagement() { initComponents(); set

我想从数据ID中获取所有值

我完成了以下操作,只得到了ID数据的第一个值。请帮助了解如何从中获取所有值

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);
    }        
}
我已经知道我的问题了。这是因为我想在jcombobox中选择id时检索所有数据…这是我的编码

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);
    }
}

有人能帮我一下这个代码有什么问题吗…

1。永远不要这样做:
catch(异常e){}
。至少打印出stacktrace。否则,您如何知道是否发生过异常?2.是时候做一些调试了。将while循环的结果打印到控制台,以查看实际提取的数据;退出while循环,它会弹出相同的内容。此外,也没有发生异常。