Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2008
    Posts
    54
    Rep Power
    0

    Default Help for iterating data from arraylist uniquely

    In my table 'tquesAnsIfo' there is data :

    ProductUid Question Answer Name

    82371 what is cost? 20% Hari
    82371 what is cost? 250$ Ram
    82371 discount 10% Manish
    82371 discount 10% Vikram


    this time there is 4 rows.any time there is 6 row or 10 rows.
    So how can i display tables row on jsp using arraylist

  2. #2
    Join Date
    Jun 2008
    Posts
    54
    Rep Power
    0

    Default Please Help...my code is...duplicate row come

    Quote Originally Posted by 82rathi.angara View Post
    In my table 'tquesAnsIfo' there is data :

    ProductUid Question Answer Name

    82371 what is cost? 20% Hari
    82371 what is cost? 250$ Ram
    82371 discount 10% Manish
    82371 discount 10% Vikram


    this time there is 4 rows.any time there is 6 row or 10 rows.
    So how can i display tables row on jsp using arraylist

    My code is :

    QuesAndAnsForm qAnsForm = new QuesAndAnsForm();
    con = DatabaseDAO.getInstance().getConnection();
    StringBuffer q4 = new StringBuffer();
    ArrayList<QuesAndAnsForm> qandanswerList = new ArrayList<QuesAndAnsForm>();
    try{
    q4.append(" select p_uid,question,answer,custname " +
    " from tquesanswerinfo t,tcustquestanswer c " +
    " where c.UID_PK = t.custid and p_uid = '"+pid+"' and t.checkforlive= '1' ");
    rs = con.createStatement().executeQuery(String.valueOf( q4));
    if(rs!=null){
    while(rs.next()){
    qAnsForm.setProdSku(rs.getString(1));
    qAnsForm.setQuestion(rs.getString(2));
    qAnsForm.setAnswer(rs.getString(3));
    qAnsForm.setCustName(rs.getString(4));

    qandanswerList.add(qAnsForm);
    }
    for(Iterator it=qandanswerList.iterator();it.hasNext();){
    System.out.println("it.next:answer"+((QuesAndAnsFo rm)it.next()).getAnswer()); System.out.println("it.next:custname"+((QuesAndAns Form)it.next()).getCustName());
    System.out.println("it.next:Question"+((QuesAndAns Form)it.next()).getQuestion());

    }

    }

    catch(Exception e){
    e.printStackTrace();
    System.out.println("Error into getForCheckLive");
    }


    Result I got duplicate rows...please give solution

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    A comment on your code:
    You only check hasNext() every three next() calls.
    You get only one data field from each object vs getting 3 from each object. Perhaps you should only do 1 next and then get the 3 items from it.

Similar Threads

  1. Replies: 2
    Last Post: 04-21-2008, 12:43 PM
  2. Iterating through ArrayList using For loop
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-20-2008, 09:53 AM
  3. Iterating through ArrayList
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-20-2008, 09:50 AM
  4. Replies: 0
    Last Post: 11-14-2007, 04:22 PM
  5. Replies: 0
    Last Post: 11-14-2007, 04:22 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
  •