我使用下面的编码使用另一个jcombobox向jcombobox添加值,我需要根据在jcombobox1中选择的值将值添加到jcombobox2而不附加值所以有人可以告诉我一种重置或清除组合框的方法选择另一个选项时的值?下面是我的编码,我是 java 和 netbeans 的新手,所以如果有人可以帮助我将不胜感激:)
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/database1", "root", "senura123");
Statement stat = (Statement) con.createStatement();
String val=jComboBox1.getSelectedItem().toString();
String check; String col;
if ("Vehicles".equals(val)){
check = "select reg_no from vehicle;";
col="reg_no";
}
else if ("Travel Guides".equals(val)){
check = "select username from travelguide;";
col="username";
}
else{
check = "select username from transportofficer";
col="username";
}
ResultSet rslt = stat.executeQuery(check);
while (rslt.next()) {
jComboBox2.addItem(rslt.getString(col));
}
}