Skip to content
Advertisement

Adding distinct data to jComboBox from database

I have a jComboBox which i want to fill up with the departments of the students in a database. Now the same department occurs many times in the table so i want each department name to go only once to the list of items. The present code i wrote is not giving the desired result. It puts the same department name multiple times on the ComboBox list. How can i solve this? My code to fetch department names is given below:

Advertisement

Answer

I guess, you need use group by in select data…

select columnName from tablename Group by columnName

Group by is like distinct

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement