Results 1 to 7 of 7
Thread: Databse items to Jcombobox
- 09-17-2009, 07:34 AM #1
Member
- Join Date
- Sep 2009
- Posts
- 9
- Rep Power
- 0
- 09-17-2009, 08:00 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
What have you tried and where exactly are you stuck?
- 09-17-2009, 08:17 AM #3
Member
- Join Date
- Sep 2009
- Posts
- 9
- Rep Power
- 0
I have Purchase table, i like add purchaseorder no column to combobox...whenever i put new purchase order that purchase order no should be automatically updated in the combo box...
Java Code:JComboBox PONO; rs1=stmt6.executeQuery("select * from Purchase"); while(rs1.next()) { uni[]=(rs1.getString(5)); // this column show error PONO=new JComboBox(uni); }
- 09-17-2009, 08:30 AM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
What did you hope to achieve with that line that shows an error?
Write a method that (inside some data access class) returns the array of data items to put into your comboxes.
Use the array returned to create a DefaultComboBoxModel that you set as the model for your combobox. The result is that SQL code does not get mixed with swing code.
- 09-17-2009, 10:15 AM #5
Member
- Join Date
- Sep 2009
- Posts
- 9
- Rep Power
- 0
shall i use getSelected item() to get the database item .... just give me one example to understand better...
Plz.....
Thanks & Regards
Pra.deep
- 09-17-2009, 10:19 AM #6
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
The getSelectedItem method has nothing to do with getting values from your database. Write a separate class with a method that gets the values from the database. That method should no nothing about Comboboxes. It must just get the values you want from the database and return the data as an array. Test that method and make sure it works as required.
You then read the API specs link I posted above to find out how to use a constructor to create a model that holds the arrays values. Set that model as your combobox's model.
- 09-17-2009, 10:50 AM #7
Member
- Join Date
- Sep 2009
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
jlist items
By bullstreetboy in forum New To JavaReplies: 6Last Post: 04-12-2009, 05:30 PM -
how to save added items in jcombobox
By kwink in forum AWT / SwingReplies: 2Last Post: 03-22-2009, 06:03 PM -
different sort of items
By jrleonard in forum SWT / JFaceReplies: 0Last Post: 12-23-2008, 02:41 PM -
Using Enumeration to get items out of the session
By Java Tip in forum Java TipReplies: 0Last Post: 01-04-2008, 09:34 AM -
Adding items to a jComboBox
By tronovan in forum New To JavaReplies: 0Last Post: 08-08-2007, 08:48 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks