title: How can I get the ID value from the database when selecting an item from a combobox?
body: <p>I have got this method that fills out my combobox:</p>
  
  <pre><code>public DefaultComboBoxModel llenarComboFamilia() throws SQLException {
      String query = "select * from familias";
      DefaultComboBoxModel df = new DefaultComboBoxModel();
      abrirConexion();
      Statement stmt = conn.createStatement();
      ResultSet rs = stmt.executeQuery(query);
      while (rs.next()) {
          //df.addElement(rs.getObject("This is the ID I need"));
          df.addElement(rs.getString("String from DB"));
      }
      cerrarConexion();
      return df;
  }
  </code></pre>
  
  <p>Then I load it with:</p>
  
  <pre><code>jComboBox2.setModel(con.llenarComboFamilia());
  </code></pre>
  
  <p>And when I click on "Register" button I have got:</p>
  
  <pre><code>private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
      Persona p = new Persona(jTextField7.getText(), 1, 
              jComboBox2.getSelectedIndex() + 1, 
              jTextField5.getText(), jTextField6.getText());
  
      con.insertarPersonasProp(p);
  
  }
  </code></pre>
  
  <p>But <code>jComboBox2.getSelectedIndex() + 1</code> does not work for me, becuase I need the ID value from the database, not the selected index.</p>
  
  <p>Any ideas?</p>