mardi 5 mai 2015

if else function using radio button show others value

I confused with this if-else because I'm new in Java & MySQL and I tried to make it by myself.

private void showCategory() {
        try {
            Statement stmt;
            stmt = con.createStatement();

            if (rbMFood.isSelected()) {
                ResultSet rs = stmt.executeQuery("SELECT * FROM menu_cat WHERE type_id = 'TYO2'");
                while (rs.next()) {
                    cmbMCat.addItem(rs.getString("menu_cat"));
                }

            } else {
                ResultSet rs = stmt.executeQuery("SELECT * FROM menu_cat WHERE type_id = 'TY01'");
                while (rs.next()) {
                    cmbMCat.addItem(rs.getString("menu_cat"));
                }

            }
        } catch (Exception e) {

        }
    }

when I run, I click food, but Drink's category who out.

enter image description here

Any help would be greatly appreciated!

Aucun commentaire:

Enregistrer un commentaire