Dear all,
This is me again, with another question......

I have SQL query like this :
SELECT CountryName, CountryID FROM MasterCountry Order By CountryName

I want to set all country names as Item and countryId as Value to jComboBox.
If I select jComboBox, I want to get the CountryID as value to save it in table.

For comparison, In .Net

Dim Item As New ListItem
Item.Value = "NY"
Item.Text = "NEW YORK"
Ctl.Items.Insert(0, Item)

The java way to do it is to create a class with attributes: CountryName, CountryID
Then create a method that runs the select-query, gets those values from the DB and puts them inside a Vector or ArrayList of that class and then of course return it.
Since you have the results you can do them whatever you want.
It is better to have separate classes that do stuff with the database and return the results. Then use those methods/results in any way you want. Don't mix inside the code queries that get the results and then manipulate them

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.