java - Copy new comboBoxModel to multiple comboBox components from single SQL Query -


i need copy combobox model in multiple java forms contains list of "states", in project list obtained pgsql server, there's 6 combobox components should display same list controled independently.

the problem each time panels load, obtains 6 times lists executing following query:

    "select distinct t_states \"states\"" 

the solution dont know how execute query once comboboxmodel , copy locally other panels required code fill obtain comboboxmodel is:

    comboboxstates.setmodel(             new combomodels().getcombomodel(                     "select distinct t_states \"states\"")); 

the class combomodels() contains function:

public comboboxmodel getcombomodel(string query)  {        try {            statement = connection.open().createstatement();            resultset = statement.executequery(query);            connection.commit();            connection.close();             combomodel = tablemodel.refreshcombo(resultset);             resultset.close();            statement.close();          } catch (sqlexception ex) {            new outbox(ex.tostring());        }        return combomodel; } 

and class tablemodels() contains function:

public comboboxmodel refreshcombo(resultset rs)         throws sqlexception {      resultsetmetadata metadata = rs.getmetadata();     int columncount = metadata.getcolumncount();      vector<vector<string>> data = new vector<>();     while (rs.next()) {         vector<string> vector = new vector<>();         (int columnindex = 1; columnindex <= columncount; columnindex++) {             vector.add(rs.getstring(columnindex));         }         data.add(vector);     }      string[] = new string[data.size()];     (int = 0; < data.size(); i++) {         a[i] = data.get(i).tostring().replaceall("[\\(\\)\\[\\]\\{\\}]", "");     }     return new defaultcomboboxmodel(a); }  } 


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -