Rima Touya Rima Touya - 2 years ago 259
SQL Question

Get value from Jtable and set it to JcomboxBox in Netbeans

I want to ask if there's a way to get the value from Jtable and set it to JcomboBox.

I insert data into database using jcomboboxes, so i want to get the value of what i inserted to database.

Im using netbeans & mysql

Answer Source

Yes you can do it.

One Way

You need to get data from JTable using getValueAt(row,column) and them you can add that value to JComboBox using addItem(value) like:


Second Way

As you are using mysql resultset to get fill the jtable, you can use that resultset to set the combobox value too like:

You can use a loadcombo() to load your combobox with database values.

void loadcombo() {
    // Your database connections 

rs= st.executeQuery("select Column from Table");
    catch(Exception e)

I suggest you to use second way

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download