Am trying to change the contents of a JComboBox - phoneModelCombo based on items selected by in another JComboBox - brandCombo. I will appreciate any resource, help that would help me fix this issue.
Here is an excerpt of what i have tried to no avail:
brandCombo.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae){ try{ try{ Class.forName("com.mysql.jdbc.Driver").newInstance(); }catch(Exception e){ JOptionPane.showMessageDialog(null, "Exception: "+e.getMessage()); } Connection con = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/phoneshopsystem","root", dbLogin.db()); final String query2 = "SELECT phoneModels FROM `phones` WHERE phoneBrand = ?"; PreparedStatement pst = con.prepareStatement(query2, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rset = pst.executeQuery(); while(rset.next()){ JComboBox bx = (JComboBox)ae.getSource(); String b = bx.getSelectedItem().toString(); pst.setString(2, b); phoneModelCombo.addItem(rset.getString ("phoneModels")); } con.close(); }catch(SQLException sql){ } } });