Results 1 to 5 of 5
  1. #1
    habiler is offline Member
    Join Date
    Sep 2016
    Posts
    44
    Rep Power
    0

    Default Jcombobox et table access

    Hello to all

    J have a table access Typedossier with two fields: nature and typic.

    I would want to populate a jCombobox Java " jCboTypeAbsence " with the Nature field.

    The problem is that nothing displays in my combobox but also that j have no message error has the compil.

    Thank you for advance

    Habiler

    Java Code:
        private void jCboTypeAbsenceActionPerformed(ActionEvent e) {
        conn = Connect.ConnectDB();
            String sql1 = "select * from Typedossier " ;
          try{
              ps = conn.prepareStatement(sql1);
              rs1 = ps.executeQuery();
              while (rs1.next()){
              jCboTypeAbsence.addItem (rs1.getString("Nature"));
              }
          
          }catch (SQLException ex){
         
          
          }
    
        }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Jcombobox et table access

    It is difficult to tell what you are actually doing. But it appears that you are trying to populate the combo
    box from within the combo box event handler. This can lead to problems if care is not taken as it can
    lock up your gui (or simply not display updates in real time). You should also print some informative message
    in your SQLException block in case something unexpected happens.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    habiler is offline Member
    Join Date
    Sep 2016
    Posts
    44
    Rep Power
    0

    Default Re: Jcombobox et table access

    He Jim

    What do you propose> i m beginner in Java and i m workimg with netbeans.
    I[ m trying many solutions but no results
    Habiler

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Jcombobox et table access

    Normally Combo boxes are populated as part of a setup. If you need to query something or read a file to populate the combo box, then simply
    get the information and do so. Here is a link on how to use combo boxes. It came from the tutorials in my signature which has other useful
    info too.

    How to use Combo Boxes

    There may be other problems too. You haven't show much code. I recommend you write a small program to get familiar with how the combo
    boxes work. If you have a problem, then we can help you with that.

    Regards,
    Jim
    Last edited by jim829; 10-27-2016 at 06:35 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Jcombobox et table access

    As jim suggests, you ought to be getting the data for populating the combo box separately from actually populating it.

    Put the data gathering code into another class, this would usually be some form of DAO (Data Access Object) which does the data gathering.
    That data gathering should be on its own thread if it's being done in reaction to the user doing something, which is what Swing Workers are for (see the tutorials jim links to, they're under swing concurrency).
    Doing this on its own thread prevents the GUI from locking up.

    If it's only populated at the start and doesn't change then that's less of a concern.

    The other advantage of creating a DAO like that is that you can test it in isolation. That is, you can make sure it actually finds the data and returns the correct values completely detached from any gui issues.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 2
    Last Post: 04-03-2013, 04:33 PM
  2. Replies: 3
    Last Post: 07-04-2012, 09:27 AM
  3. Replies: 0
    Last Post: 05-14-2012, 04:57 PM
  4. Replies: 2
    Last Post: 07-30-2008, 12:33 PM
  5. Replies: 1
    Last Post: 02-01-2008, 01:21 PM

Posting Permissions

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