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

    Default The outer loop doesnt stop running

    if (userid.getText().equalsIgnoreCase("")) {
    JOptionPane.showMessageDialog(null, "Type in your user id please!!");
    userid.requestFocus();
    } else {

    try {

    ps = connection.connection.prepareStatement("SELECT u.user_code, r.user_code FROM usr_pln_rghts r,users u");

    String user = "";

    ResultSet rs = ps.executeQuery();
    while (rs.next()) {
    x = userid.getText();
    user = rs.getString("user_code");
    usr = user.trim();
    if (x.equals(usr)) {

    ps = connection.connection.prepareStatement("Select U.user_code , P.plan_code , P.pln_prd_TCDE , U.PLN_BOT_LVL , U.DIM_CODE FROM PLAN_DETAIL P,USR_PLN_RGHTS U ");

    ResultSet rec = ps.executeQuery();

    while (rec.next()) {
    String usercd = rec.getString("user_code");
    String plancd = rec.getString("plan_code");
    String plnprd = rec.getString("pln_prd_TCDE");
    String plnbotlvl = rec.getString("PLN_BOT_LVL");
    String dimcode = rec.getString("DIM_CODE");
    model.addElement(usercd);
    model.addElement(plancd);
    model.addElement(plnprd);
    model.addElement(plnbotlvl);
    model.addElement(dimcode);

    chooseplannameCmb.addItem(plancd);
    queryResltList.add(usercd +";"+ plancd+";" + plnprd+";" + plnbotlvl+";" + dimcode);


    }
    connection.connection.close();
    ps.close();

    }

    }


    } catch (SQLException ex) {
    Logger.getLogger(userAccessUI.class.getName()).log (Level.SEVERE, null, ex);
    }

    }

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

    Default

    i dont know what i did wrong in this code about. i need help plz

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,544
    Rep Power
    23

    Default

    Have you tried debugging the code by printing out the variables to see what is being read at each place in the loop?

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

    Default

    oh the problem was that there were lot of records in the database that means it was still reading those records and after sometime it does stop.

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

    Red face Trasfer all items from one List to another

    List queryResltList = new List();
    List actionListList= new List();


    //i can transfer one item :
    //transfering from queryResltList to actionListList.

    but now i want all items to be moved from one List to another by clicking the button.


    if (e.getSource()==Btnname)
    {
    queryResltList.add(actionListList.getSelectedItem( ));
    actionListList.remove(actionListList.getSelectedIn dex());

    }
    else if(e.getSource==Btnname)
    {

    // i need help here to transfer all items without selection.


    }
    Last edited by Bulelakes; 08-19-2010 at 02:57 PM. Reason: i used the wrong statement

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,544
    Rep Power
    23

    Default

    A problem with your code as shown is the getSource() method returns a reference to the object sensing the event.
    If your button were defined as follows:
    Button buttonLabel = new Button(" a butn");

    Then getSource would return a reference to the object pointed to by buttonLabel when the button was clicked.
    e.getSource() == buttonLabel // the same values
    This can be used in an actionPerformed method to determine which button was pressed.

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

    Default

    Norm

    I need to know how to transfer all items from one List to another

    i need the else if code leave the first if statement.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,544
    Rep Power
    23

    Default

    Does your first "if" statement work?

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

    Default

    Yes indeed but im using statement like this
    Btnname is a button name
    if (e.getSource()==Btnname)
    {

    }

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,544
    Rep Power
    23

    Default

    if (e.getSource()==">")
    {
    That's not what you posted???
    Wastes everyones time posting code that you are NOT using.

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

    Default

    im sorry i thought that was gona do the same thing
    so can u plz help me with the second "if" statement.

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

    Default

    my user interface looks like this

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,544
    Rep Power
    23

    Default

    Copy the code to the forum putting it inside of code tags to preserve the formatting.

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

    Default

    :confused:here is my code below:

    XML Code:
    //get the user code from the user and compare it with the one in database
                    if (userid.getText().equalsIgnoreCase("")) {
                        JOptionPane.showMessageDialog(null, "Type in your user id please!!");
                        userid.requestFocus();
                    } else {
                    try {
                     reslts   ="SELECT u.user_code, r.user_code FROM usr_pln_rghts r,users u";
                        String user = "";
                         rs = statement.executeQuery(reslts);
                          while (rs.next()) {
                            x = userid.getText();
                            user = rs.getString("user_code");
                            usr = user.trim();
                            String usrcode=  x.trim();
    
             //if the user code matches the one in database display data where usercode is equal to the one entered by the user
                            if (x.equals(usr)) {
                                 
                                 userids = "select user_code , plan_code,pln_bot_lvl, dim_code from usr_pln_rghts "+
                                        " where user_code ="+"'"+usrcode+"'";
                                       
                                rec = statement.executeQuery(userids);                            
                                 while (rec.next()) {
                                   
                                    String usercd = rec.getString("user_code");
                                    String plancd = rec.getString("plan_code");
                                    String plnbotlvl = rec.getString("PLN_BOT_LVL");
                                    String dimcode = rec.getString("DIM_CODE");
                                    model.addElement(usercd);
                                    model.addElement(plancd);
                                    model.addElement(plnbotlvl);
                                    model.addElement(dimcode);
                                    chooseplannameCmb.addItem(plancd);
                                    
                       //display the the details in queryResultList.
                                    queryResltList.add(usercd + ";" + plancd + ";"+ plnbotlvl + ";" + dimcode);
                                  
                              
    
            }
                             
       }
    //move selected item from queryResultList to  actionListList
          if (e.getSource()==cpyrytBtn)
            {     
                 queryResltList.add(actionListList.getSelectedItem());
                  actionListList.remove(actionListList.getSelectedIndex());
    
            }
    
    //move all items from queryList to actionList
      if (e.getSource()==cpyallrytBtn)
                {
    
                // i need this code here please!!
               //i need the statement to copy all items
                
    
                }

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,544
    Rep Power
    23

    Default

    The code you've posted looks like random bits and pieces copied from your program that left out a lot of things.
    For example where are the variables: e, queryResltList, actionListList defined?

    Where is the "outer loop that doesn't stop running?

    A comment asks: //i need the statement to copy all items

    Copy from where to where?

  16. #16
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,544
    Rep Power
    23

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

    Smile

    Thank u so much for trying to help me ,finally i got it working below is my code:

    Java Code:
     int i =actionListList.getSelectedIndex();
                 String items[];
                 while(i==-1)
                  {
    
                       items =(String[]) actionListList.getItems();
    
                    for(int j=0;j<items.length;j++){
    
                          queryResltList.add(items[j]);
                          actionListList.removeAll();
                    }
                          break;
    
                   }

Similar Threads

  1. Use stop button to stop moving (stop timers) on JPanel
    By mneskovic in forum New To Java
    Replies: 3
    Last Post: 07-23-2010, 12:50 PM
  2. Replies: 3
    Last Post: 01-29-2010, 08:05 AM
  3. How do I stop or kill a running thread when a condition is true
    By chikaman in forum Threads and Synchronization
    Replies: 3
    Last Post: 12-21-2009, 11:07 PM
  4. Infinite running loop problems
    By BigDummy in forum New To Java
    Replies: 5
    Last Post: 10-14-2009, 06:39 AM
  5. How to stop/pause running third party exe?
    By 2bGeek in forum AWT / Swing
    Replies: 3
    Last Post: 02-28-2009, 07:26 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
  •