Setting the value of a JCombobox from a database

Setting the value of a JCombobox from a database

Post by J. Todd Slac » Sat, 05 Oct 2002 02:41:50



Hi

Say I have a JCombobox and I save its SelectedValue to a database table. (it
is populated by a vector)

Now I want to recall this record from the database., How do I set my
combobox to the value from my table?

 I see setSelectedIndex and setSelectedItem, but how do I tell is that the
value in my database table is to be set in the JcomboBox?

Thoughts? Examples?

-Jason

 
 
 

Setting the value of a JCombobox from a database

Post by Linda Radeck » Sat, 05 Oct 2002 07:12:57



> Hi
> Say I have a JCombobox and I save its SelectedValue to a database table. (it
> is populated by a vector)
> Now I want to recall this record from the database., How do I set my
> combobox to the value from my table?
>  I see setSelectedIndex and setSelectedItem, but how do I tell is that the
> value in my database table is to be set in the JcomboBox?

Well, you can query the table in the database to get the needed value:

"SELECT <column> FROM <table> WHERE <column> = '<yourValue>'";

and set the retrieved value via ResultSet.next() then

if (rs.next()) {
   combo.setSelectedItem(rs.getString(1));

Quote:}

Have you meant that? I populate the ComboBoxModel with the data
from the database, thus I get the new updated values automatically
then, actually. Hope this helps

Linda
--

* ). and the stars over us was sparkling ever so fine; and down by the
village was the river, a whole mile broad, and awful still and grand.
~-_-..__...---._..-'~...The Adventures Of Huckleberry Finn *Mark Twain