title: how to pass from combobox value to
body: <p>Somehow I managed to make that id isn't shown in the combobox, but then how to make that when I press the button ok I could get the id value? Using <code>String from = (String) jComboBox1.getSelectedItem();</code> when the button is pressed doesn't work. I get <code>String code = (String) item.getValue();</code> the id I needed, but how do I pass it to the next query?</p>
  
  <pre><code>public void select() {
  
           try {
              String sql = "select * from category";
              pst = con.prepareStatement(sql);
              rs = pst.executeQuery();
  
              while (rs.next()) {
  
          jComboBox1.addItem(new Item&lt;String&gt;(rs.getString("mkid"), rs.getString("name")));
  
              }
  
          } catch (Exception e) {
              JOptionPane.showMessageDialog(null, e);
          }
  
          jComboBox1.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  JComboBox jComboBox1 = (JComboBox) e.getSource();
                  Item item = (Item) jComboBox1.getSelectedItem();
                  String code = (String) item.getValue();
                  System.out.println(code);
              }
          });
  
  
      }
  
  
      The item
  
       public class Item&lt;V&gt; implements Comparable&lt;Item&gt;
       {
      private V value;
      private String description;
  
  
      public Item(V value, String description)
      {
          this.value = value;
          this.description = description;
      }
  
  
      public V getValue()
      {
          return value;
      }
  
      public String getDescription()
      {
          return description;
      }
  
      public int compareTo(Item item)
      {
          return getDescription().compareTo(item.getDescription());
      }
  
      @Override
      public boolean equals(Object object)
      {
          Item item = (Item)object;
          return value.equals(item.getValue());
      }
  
      @Override
      public int hashCode()
      {
          return value.hashCode();
      }
  
  
      @Override
      public String toString()
      {
          return description;
      }
  </code></pre>