Results 1 to 5 of 5
  1. #1
    Bulelakes is offline Member
    Join Date
    Jul 2010
    Posts
    32
    Rep Power
    0

    Default Jcombobox + jdbc

    Java Code:
    Im trying to populate a Jcombobox with the data from a table 
    and use that data to display related data  fields into the TextFields :
    ----------------------------------------------------------------------
    //Here i load the data into the Jcombobox it works perfect.
    
     plan_name ="select  DISTINCT(plan_code),pln_bot_lvl, dim_code,PLN_MEM_TCDE,RW_MODE from usr_pln_rghts";
    
             try {
               connection.statement = connection.connection.createStatement();
                ResultSet r = connection.statement.executeQuery(plan_name);
              while(r.next())
              {
                  String plns = r.getString("plan_code");
                  planNameCmb.addItem(plns);
    
              }
    --------------------------------------------------------------------
    
    //Here i want to get the combobox selected item and display the related data into the TextFields but it does not work i dnt knw what might be a problem .
    
     if (e.getSource()==planNameCmb)
    //
     {
        // planNameCmb.removeAllItems();
                try {
                    connection.statement = connection.connection.createStatement();
                    pln_name = "select pln_bot_lvl,RW_MODE, dim_code,PLN_MEM_TCDE, from usr_pln_rghts where plan_code = " + "'"+planNameCmb.getSelectedItem()+"'";
                    ResultSet rc = connection.statement.executeQuery(plan_name);
                    while (rc.next()) {
                    levelTxt.setText(rc.getString("pln_bot_lvl"));
                    rightsTxt.setText(rc.getString("RW_MODE"));
                    modeTxt.setText(rc.getString("dim_code"));
                    memTxt.setText(rc.getString("PLN_MEM_TCDE"));
    
                  
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(userAccessUI.class.getName()).log(Level.SEVERE, null, ex);
                } }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Are you getting any exceptions thrown?
    What does "does not work" mean?

    As a side note, there's no point SELECTing all those rows in the first SQL statement if you're only actually using the plan_code. Waste of bandwidth.

    Also for the second query, you should be using a PreparedPreparedStatement (Java Platform SE 6)Statement rather than concatenating the plan code String into the query. Not knowing what that String is, it is possible that that is your problem.

  3. #3
    Bulelakes is offline Member
    Join Date
    Jul 2010
    Posts
    32
    Rep Power
    0

    Default

    Java Code:
    i did try to use preparedStatement and its throwing this error
    
    " java.sql.SQLException: ORA-00936: missing expression" 
    
    if (e.getSource()==planNameCmb)
    
     {
       
                try {
                  PreparedStatement pstmt = connection.connection.prepareStatement("select pln_bot_lvl,RW_MODE, dim_code,PLN_MEM_TCDE, from usr_pln_rghts "+
                   " WHERE plan_code = ?");
    
            pstmt.setString(1, (String)planNameCmb.getSelectedItem()) ;
         
                    ResultSet rc = pstmt.executeQuery();
                    while (rc.next()) {
                    levelTxt.setText(rc.getString("pln_bot_lvl"));
                    rightsTxt.setText(rc.getString("RW_MODE"));
                    modeTxt.setText(rc.getString("dim_code"));
                    memTxt.setText(rc.getString("PLN_MEM_TCDE"));
    
                  
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(userAccessUI.class.getName()).log(Level.SEVERE, null, ex);
                } }

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    "select pln_bot_lvl,RW_MODE, dim_code,PLN_MEM_TCDE, from..."
    You have a comma in the wrong place after PLN_MEM_TCDE.

  5. #5
    Bulelakes is offline Member
    Join Date
    Jul 2010
    Posts
    32
    Rep Power
    0

Similar Threads

  1. Replies: 2
    Last Post: 12-10-2009, 02:58 PM
  2. JCombobox
    By daniel50096230 in forum NetBeans
    Replies: 1
    Last Post: 09-21-2008, 01:23 PM
  3. JComboBox
    By Fosters in forum AWT / Swing
    Replies: 0
    Last Post: 08-10-2008, 02:22 PM
  4. Replies: 0
    Last Post: 04-01-2008, 11:17 AM
  5. Replies: 0
    Last Post: 09-28-2007, 01:56 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
  •