Hey Guys,

What i want it to do :

  1. Combobox is displayed with a list of countys ie Limerick Dublin Cork
  2. Choose County brings up second Combobox with countys towns and villages.
  3. Hit search brings up relevant towns and vilages from the county chosen.

What it does:
1. Loads countys
2. chose county
3. Second box pops up but with no values in the combobox nd it then crashs and informs me that County_ID cannot be found and "severe null"

Code to fill First Combobox with the Countys (Works fine)

 public Activities_Area_Search1() {
        try {
            initComponents();
             JdbcRowSetImpl rowSet = new JdbcRowSetImpl();

                rowSet.setUrl("xxxxxxxxxxxxxxxx");
                rowSet.setUsername("xxx");
                rowSet.setPassword("xxx");



                rowSet.setCommand("SELECT DISTINCT County_ID FROM activities ");
                rowSet.execute();

                while (rowSet.next()) {
                    String A2 = rowSet.getString("County_ID");
                    ComboBox1.addItem(A2);

                }
        } catch (SQLException ex) {
            Logger.getLogger(Activities_Area_Search1.class.getName()).log(Level.SEVERE, null, ex);
        }
    }



    private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             

       Activities_Area_Search2 AR2 = new Activities_Area_Search2(ComboBox1.getSelectedItem());
        AR2.setVisible(true);
        dispose();
    }                                            

Code For second Combobox that shud contain relevant towns and villages but doesn't .

  public Activities_Area_Search2(Object County_ID) {
        try {
            initComponents();
             JdbcRowSetImpl rowSet = new JdbcRowSetImpl();

                rowSet.setUrl("jdbc:mysql://localhost:3306/ireland");
                rowSet.setUsername("root");
                rowSet.setPassword("MySQL5");



                rowSet.setCommand("SELECT Town FROM activities WHERE County_ID = '"+ County_ID + "'");
                rowSet.execute();

                while (rowSet.next()) {
                    String A1 = rowSet.getString("County_ID");
                    ComboBox.addItem(A1);

                }
        } catch (SQLException ex) {
            Logger.getLogger(Activities_Area_Search2.class.getName()).log(Level.SEVERE, null, ex);
        }
    }


        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Activities_Area_Search2("County_ID").setVisible(true);
            }
        });
    }

So my problem is with the second piece of code the combo box shows up empty and as far as i see everything is ok ?

16: String A1 = rowSet.getString("County_ID");

Maybe this should be String A1 = rowSet.getString("Town"); ?

U are a Legend :) Thanks a million :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.