Results 1 to 5 of 5
- 04-21-2011, 01:36 PM #1
How to populate a JcomboBox with dynamic data from database
Hi guyz,
I want to populate a jcomboBox with data from database everytime i run y program. I am able to get the list from a database but am unable to display it in the combobox.
Any ideas on how i can achieve this will be highly appreciated.
Am using netbeans.
Cheerz!!We Learn Through Mistakes..,
Manfizy:rolleyes:
-
How do you try to display it in the JComboBox? Do you use a DefaultComboBoxModel object? Can we see your code?
- 04-21-2011, 01:53 PM #3
Well; i have not used the DefaultComboBoxModel object because i do not know how to use it.
Below is the code that am using
Java Code:public void populateComboBox(){ String query; // Vector fileList = new Vector(); try { statement = getConn.getConnection().createStatement(); query = "SELECT AcademicYears FROM PathConfig "; resultSet = statement.executeQuery(query); ResultSetMetaData rsmdt = resultSet.getMetaData(); int columns = rsmdt.getColumnCount(); while(resultSet.next()){ Vector row = new Vector(); for(int i = 1; i <= columns; i++){ //row.addElement(resultSet.getString(i)); fileList.addElement(resultSet.getString(i)); } //fileList.addElement(row); } statement.close(); getConn.conn.close(); } catch (SQLException ex) { Logger.getLogger(FrmTranscript.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("FILE LIST :"+fileList); jComboBox3 = new JComboBox(fileList); }We Learn Through Mistakes..,
Manfizy:rolleyes:
-
I would create a class to hold each row's worth of data and give the class a meaningful toString() method for this is what the combo box will display. I'd then create a DefaultComboBoxModel object and iterate through the resultset creating a new object of the row class and then placing these objects into the model via its addElement method. I'd then make my combo box's model my filled model object.
- 04-22-2011, 07:24 PM #5
Similar Threads
-
Dynamic data model in JComboBox
By agreed in forum AWT / SwingReplies: 5Last Post: 11-15-2009, 08:30 PM -
Help Pls!! Jcombobox populate with mysql
By kwink in forum AWT / SwingReplies: 1Last Post: 03-23-2009, 04:11 AM -
populate jCombobox with database data
By joeyxaza in forum JDBCReplies: 1Last Post: 02-08-2009, 12:09 AM -
populate jCombobox with database data
By joeyxaza in forum JDBCReplies: 0Last Post: 01-19-2009, 04:30 PM -
how to populate html:select with values from database
By sathya_k_83 in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 11-07-2007, 10:53 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks