城市和州组合框

wqnecbli  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(168)

我有两个表,名称为city和state
城市

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

我用了组合框,我有2个
组合框1

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();
    }
}

第二个组合框2

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 代码错误?在运行程序时告诉我java中的错误

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题