Your question is somewhat incomplete, but my guess is that your JComboBox is populated with String. If so it would likely be better for you to populate the JComboBox (or better, its model) with objects of a custom class that combines your ProductID with a ProductName. To have the combobox display the name, you will need to either give your class a toString() method that returns the name, or give your combo box a cell renderer that shows the name.
Edit
For example, create a class, MyComboItem, give it two String fields that you fill from your database, give it a toString()
method that shows the product name, and fill your JComboBox with items of this type:
class MyComboItem {
private String productId;
private String productName;
public MyComboItem(String productId, String productName) {
this.productId = productId;
this.productName = productName;
}
public String getProductId() {
return productId;
}
public String getProductName() {
return productName;
}
@Override
public String toString() {
return productName;
}
}
Edit 2
Which can be used like so:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
public class ComboItemTest {
public static void main(String[] args) {
DefaultComboBoxModel<MyComboItem> comboModel =
new DefaultComboBoxModel<MyComboItem>();
// note that here you would fill the model with data from your database ***
comboModel.addElement(new MyComboItem("x1234A", "Product 1"));
comboModel.addElement(new MyComboItem("x1235A", "Product 2"));
comboModel.addElement(new MyComboItem("x1236A", "Product 3"));
comboModel.addElement(new MyComboItem("x1237A", "Product 4"));
comboModel.addElement(new MyComboItem("x1238A", "Product 5"));
comboModel.addElement(new MyComboItem("x1239A", "Product 6"));
final JComboBox<MyComboItem> combobox = new JComboBox<MyComboItem>(comboModel);
combobox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
MyComboItem item = (MyComboItem) combobox.getSelectedItem();
if (item != null) {
System.out.printf("You've selected Product Name: %s, Product ID: %s%n",
item.getProductName(), item.getProductId());
}
}
});
JOptionPane.showMessageDialog(null, new JScrollPane(combobox));
}
}
Edit 3
In your case, you'd fill your model with information from the ResultSet. Perhaps something like:
ResultSet result = statement.executeQuery();
while(result.next()){
String productName = result.getString(1);
String productId = result.getString(2); // ???? not sure if this is valid
MyComboItem comboItem = new MyComboItem(productId, productName);
comboModel.addElement(comboItem);
}