以下のコーディングを使用して、別の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));
}
}