我使用下面的编码使用另一个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));
}
}