Set / Get jComboBox value and Item.

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2007
Posts: 181
Reputation: Kusno is an unknown quantity at this point 
Solved Threads: 15
Kusno's Avatar
Kusno Kusno is offline Offline
Junior Poster

Set / Get jComboBox value and Item.

 
0
  #1
Apr 10th, 2008
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)
NEVER NEVER NEVER GIVE UP
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,706
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 228
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: Set / Get jComboBox value and Item.

 
-1
  #2
Apr 10th, 2008
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
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC