title: How can I fill a combobox with values in a database?
body: <p>how to insert a combobox with values ​​from the data base
  I want to select from the database and add in the combobox
  I have two class:</p>
  
  <p><strong>constructor Database() first class</strong> </p>
  
  <pre><code>//constructeur 
  Database()   
                    {  
  
   void remplir_Jcomb() {
             Connection conn = null;
             Statement  st = null;
             String rq1 = "SELECT region  FROM  rg";
             String rq2 = "SELECT ACTELS  FROM  rg";
  
          // - Paramètres de connexion à la base de données
             String url = "jdbc:mysql://localhost/réseau";
             String login = "root";
             String password = "";
             String driver = "com.mysql.jdbc.Driver";
  
             try {
  
              //comboBox_gouver.removeAllItems();
                 try {
                      Class.forName(driver);
                      conn = DriverManager.getConnection(url,login,password);
                      } catch (ClassNotFoundException e) {
                          e.printStackTrace();
                           }
  
                 st = conn.createStatement();
                 ResultSet rs1 = st.executeQuery(rq1);
                 ResultSet rs2 = st.executeQuery(rq2);
  
                 while ((rs1.next())&amp;&amp;(rs2.next())) {
                  comboBox_gouver.addItem(rs1.getString(1));
                  comboBox_ACTELS.addItem(rs2.getString(1));
                 }
                 st.close();
                 rs1.close();
                 rs2.close();
                 conn.close();
  
             }  catch (SQLException e) { 
                  e.printStackTrace();}
  
              }
          }
  </code></pre>
  
  <p><strong>interface swing second class which contains two JComboBox</strong> 
  call constructor Database()</p>
  
  <pre><code>private Database BD= new Database();  
      public Region() {
  
  
  //first JComboBox
      comboBox_gouver = new JComboBox&lt;String&gt;();
              BD.remplir_Jcomb();
                  sl_contentPanel.putConstraint(SpringLayout.NORTH, lbl_gouver, 5, SpringLayout.NORTH, comboBox_gouver);
                  sl_contentPanel.putConstraint(SpringLayout.NORTH, comboBox_gouver, 5, SpringLayout.NORTH, contentPanel);
                  sl_contentPanel.putConstraint(SpringLayout.WEST, comboBox_gouver, 16, SpringLayout.EAST, lbl_gouver);
                  sl_contentPanel.putConstraint(SpringLayout.EAST, comboBox_gouver, -26, SpringLayout.EAST, contentPanel);
                  contentPanel.add(comboBox_gouver);
  
  comboBox_ACTELS = new JComboBox&lt;String&gt;();
          sl_contentPanel.putConstraint(SpringLayout.NORTH, lbl_ACTELS, 5, SpringLayout.NORTH, comboBox_ACTELS);
          sl_contentPanel.putConstraint(SpringLayout.NORTH, comboBox_ACTELS, 6, SpringLayout.SOUTH, comboBox_gouver);
          sl_contentPanel.putConstraint(SpringLayout.WEST, comboBox_ACTELS, 90, SpringLayout.EAST, lbl_ACTELS);
          sl_contentPanel.putConstraint(SpringLayout.SOUTH, comboBox_ACTELS, -29, SpringLayout.SOUTH, contentPanel);
          sl_contentPanel.putConstraint(SpringLayout.EAST, comboBox_ACTELS, -26, SpringLayout.EAST, contentPanel);
          contentPanel.add(comboBox_ACTELS);
  }}
  </code></pre>
  
  <p><strong>erreur:</strong></p>
  
  <pre><code>java.sql.SQLException: Operation not allowed after ResultSet closed
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
      at com.mysql.jdbc.ResultSetImpl.checkClosed(ResultSetImpl.java:794)
      at com.mysql.jdbc.ResultSetImpl.next(ResultSetImpl.java:7139)
      at tn.pack.ACTEL.Database.remplir_Jcomb(Database.java:94)
      at tn.pack.ACTEL.Region.&lt;init&gt;(Region.java:75)
      at tn.pack.ACTEL.Region.main(Region.java:41)
  </code></pre>