java - How do I insert data from mysql into the combobox? -


what's wrong code here?

i'm trying insert data mysql combobox in netbean

private void btnsandoghmousepressed(java.awt.event.mouseevent evt) {                                             try {         string query = "select `accounttype` `account`";          con = connect.connectdb();         preparedstatement stm = con.preparestatement(query);          pst = con.preparestatement(query);                         resultset rs = pst.executequery(query);         arraylist<string> groupnames = new arraylist<string>();          while (rs.next()) {              string groupname = rs.getstring(4);              groupnames.add(groupname);         }          defaultcomboboxmodel model = new defaultcomboboxmodel(groupnames.toarray());         cmbsemetarid.setmodel(model);         rs.close();         } catch (sqlexception e) {     system.err.println("connection error! it's date");     } } 

you problems try use model way or using vector. better try like,

  private void btnsandoghmousepressed(java.awt.event.mouseevent evt){                                             try {         string query = "select `accounttype` `account`";          con = connect.connectdb();         preparedstatement stm = con.preparestatement(query);          pst = con.preparestatement(query);                         resultset rs = pst.executequery(query);         defaultcomboboxmodel model = new defaultcomboboxmodel();         while (rs.next()) {              string groupname = rs.getstring(4);              model.add(groupname);         }           cmbsemetarid.setmodel(model);         rs.close();         } catch (sqlexception e) {     system.err.println("connection error! it's date");     } } 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -