Results 1 to 8 of 8
  1. #1
    raj reddy is offline Member
    Join Date
    Apr 2008
    Posts
    31
    Rep Power
    0

    Default How to fetch an arralist element (i need the code)

    WE HAVE TO CALL THE "SEL1" element IN THE PUBLI STATIC VOID MAIN METHOD.


    [ "SEL1" element is located in an array in the public List fetchTicketkey1() method ie

    al.add(rs.getInt("sel1")]










    public class Keno {


    public List fetchTicketkey1() {

    List al = new ArrayList();

    try {


    pstmt=con.prepareStatement("select * from draw );

    rs=pstmt.executeQuery();

    while(rs.next()) {

    al.add(rs.getInt("sel1"));
    al.add(rs.getInt("sel2"));


    }


    } catch(Exception e) {

    } return al;
    }


    public static void main(String[] args) {


    Keno ken = new Keno();


    List al = (List) ken.fetchTicketkey1();





    }}(i need the code)

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    raj reddy is offline Member
    Join Date
    Apr 2008
    Posts
    31
    Rep Power
    0

    Default

    hi Eranga

    Thks for u r reply

    how can we call the sel1 variable

    /* ie located in al.add(rs.getInt("sel1"))*/

    in the public static void main method

    system.out.println( " the value of sel1 is " + al.sel1) //this is showing error


    i need the correct code

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    raj reddy is offline Member
    Join Date
    Apr 2008
    Posts
    31
    Rep Power
    0

    Default

    yes, i need that element in the


    public static void main method



    for example like this ::: system.out.println( " the value of sel1 is " + al.sel1) //this is showing error

  6. #6
    raj reddy is offline Member
    Join Date
    Apr 2008
    Posts
    31
    Rep Power
    0

    Default

    Hi Eranga


    Did u got the code


    if any queries reply me

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by raj reddy View Post
    yes, i need that element in the


    public static void main method



    for example like this ::: system.out.println( " the value of sel1 is " + al.sel1) //this is showing error
    Yes, it's wrong. Get the element of the al list, you have to refer the index of that. Say sel1 is in the 0th place in the list. To get the value,

    Java Code:
    system.out.println( " the value of sel1 is " + al.get(0));

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by raj reddy View Post
    Hi Eranga


    Did u got the code


    if any queries reply me

    Did you read any document relating to this. And also are you working on a Java IDE? If so, you comes with compile errors. Did you read them carefully?

Similar Threads

  1. How to use Idref Element and its advantages
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-30-2008, 10:04 AM
  2. Max element in an Array
    By mew in forum New To Java
    Replies: 5
    Last Post: 12-03-2007, 05:26 PM
  3. How to use Idref Element and its advantages
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 09-26-2007, 08:37 PM
  4. a no such element exception
    By headlice1 in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:36 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
  •