Results 1 to 7 of 7
  1. #1
    pra.deep is offline Member
    Join Date
    Sep 2009
    Posts
    9
    Rep Power
    0

    Post Databse items to Jcombobox

    Hi...Everyone..:)

    I need to know how to add database items to jcombobox....

    Help me.. to solve this ...

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    What have you tried and where exactly are you stuck?

  3. #3
    pra.deep is offline Member
    Join Date
    Sep 2009
    Posts
    9
    Rep Power
    0

    Default

    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);        
                  }

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    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.

  5. #5
    pra.deep is offline Member
    Join Date
    Sep 2009
    Posts
    9
    Rep Power
    0

    Default

    shall i use getSelected item() to get the database item .... just give me one example to understand better...

    Plz.....


    Thanks & Regards

    Pra.deep

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    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.

  7. #7
    pra.deep is offline Member
    Join Date
    Sep 2009
    Posts
    9
    Rep Power
    0

Similar Threads

  1. jlist items
    By bullstreetboy in forum New To Java
    Replies: 6
    Last Post: 04-12-2009, 05:30 PM
  2. how to save added items in jcombobox
    By kwink in forum AWT / Swing
    Replies: 2
    Last Post: 03-22-2009, 06:03 PM
  3. different sort of items
    By jrleonard in forum SWT / JFace
    Replies: 0
    Last Post: 12-23-2008, 02:41 PM
  4. Replies: 0
    Last Post: 01-04-2008, 09:34 AM
  5. Adding items to a jComboBox
    By tronovan in forum New To Java
    Replies: 0
    Last Post: 08-08-2007, 08:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •