Am trying to refresh my ComboBox field with the following code with values from my database:
public ComboBoxModel phoneIdCombo(DefaultComboBoxModel model){ try{ try{ Class.forName("com.mysql.jdbc.Driver").newInstance(); }catch(Exception e){ JOptionPane.showMessageDialog(null, "Exception: "+e.getMessage()); } con = DriverManager.getConnection("jdbc:mysql://localhost:3306/phoneshopsystem", "root", dbLogin.db()); stm = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); rset = stm.executeQuery("SELECT phoneID FROM `phones`"); while(rset.next()){ model.addElement(rset.getInt(1)); } con.close(); }catch(SQLException sql){ JOptionPane.showMessageDialog(null, "SQL Exception: "+sql.getMessage()); } return model; }
The code works fine initially, but when i click on the refresh button, i get this in the ComboBox: javax.swing.DefaultComboBoxModel@1a38598 instead of the supposed values. Is that an exception? or something else?