Link to home
Start Free TrialLog in
Avatar of namsu55
namsu55Flag for United Kingdom of Great Britain and Northern Ireland

asked on

How do I retrieve the value from the ComboBox which binds to the database.

In Netbeans I currently have a ComboBox. I bind the ComboBox to a table, it collects a column for me. How do I get the value of that column and use it throughout the program. I want to take for instance whatever is selected from the ComboBox, the primary key or foreign key. Then I can use that information on manual queries to the database to fill in other areas of the JFrame.
combodb.JPG
ASKER CERTIFIED SOLUTION
Avatar of Kin Fat SZE
Kin Fat SZE
Flag of Hong Kong image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of namsu55

ASKER

Hi fsze88 that worked. Please view the image. Do you know how to get the specific primary key value if I do click on one out of the list, as I will want to store it inside a variable. I get the classname and tablename showing up as well as the primary keys.
combo.bmp
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
   private void jComboBox1_itemStateChanged(ItemEvent e) {
        String comboBoxValue;
        String Parameter;
        String[] pair;
       
        int beginIndex, endIndex;
        comboBoxValue = String.valueOf( jComboBox1.getItemAt(jComboBox1.getSelectedIndex() ));
        beginIndex = comboBoxValue.indexOf("[") +1;
        endIndex = comboBoxValue.indexOf("]");
        Parameter = comboBoxValue.substring(beginIndex,endIndex);
        System.out.println("Parameter : " + Parameter);
        pair = Parameter.split("=");
        System.out.println("value of figher : " + pair[1]);
//        System.out.println(e.toString() + e.getStateChange());
//        System.out.println(jComboBox1.getItemAt(jComboBox1.getSelectedIndex() )) ;
    }
:-)