【发布时间】:2014-01-20 03:06:55
【问题描述】:
我有两个组合框...第一个显示酒店的城市,第二个显示基于在第一个组合框中选择的城市的酒店名称。第一个组合框工作正常。第二个节目仅适用于第一个选定的城市。在第一个组合框中更改城市后,它不会对自身进行更改!为了能够通过更改第一个组合框来查看第二个组合框的更改,我必须在此代码中添加什么。
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/JEREN","root","");
Statement stat = con.createStatement();
String City_Selected = jComboBox1.getSelectedItem().toString();
String select_HN = "select name from tbl_Hotel where city = '"+City_Selected+"';";
ResultSet rs = stat.executeQuery(select_HN);
while (rs.next())
{
String hotel_name = rs.getString("name");
// jLabel3.setText(hotel_name);
jComboBox2.addItem(hotel_name);
}//end while
rs.close();
stat.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
【问题讨论】: