我有2个表,名称分别为“城市和州”
城市
id_city | name_city
1 | JED
2 | RUD
3 | DMM
状态
id_state | id_for_city | name_state
1 | 1 | JED1
2 | 1 | JED2
3 | 2 | RUD1
4 | 2 | RUD2
我用过ComboBox,我有2张
combobox1
public void Filecombo() {
try {
String sql = "select name_city from city";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next()) {
options.add(rs.getString("name_city"));
}
comboCity.setItems(options);
pstmt.close();
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
第二个comboBox2
public void Filecombo2() {
try {
String sq2 = " select * from state,city where state.id_for_city= city.id_city";
pstmt2 = conn.prepareStatement(sq2);
rs = pstmt2.executeQuery();
while (rs.next()) {
options2.add(rs.getString("name_state"));
}
comboBranch.setItems(options2);
pstmt.close();
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
当我选择combobox1时,它将出现在所有城市
但是当我选择combobox2时不显示值
我不知道我认为String sq2
代码有什么问题?
并在运行程序