Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: The record from database can't be retrieved

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default The record from database can't be retrieved

    I want to take record from database to my table in jsp page, but when run it, i have an error that say java.sql.SQLException: After end of result set, here is my code :
    public String viewDataRegistrasi() throws SQLException{
    String address="";
    String query = "select*from pegawai";
    System.out.println(query);
    ResultSet rs = database.getInstance().executeSelectQuery(query);
    ArrayList DataList = new ArrayList();
    pegawai viewdata;
    String idpeg = "";
    while(rs.next()){
    viewdata = new pegawai();
    viewdata.setNik(rs.getString(1));
    viewdata.setNama(rs.getString(2));
    viewdata.setTempatlahir(rs.getString(3));
    viewdata.setTanggallahir(rs.getString(4));
    viewdata.setEmail(rs.getString(5));
    viewdata.setAlamat(rs.getString(6));
    viewdata.setPosisi(rs.getString(7));
    DataList.add(viewdata);
    }
    request.setAttribute("viewRegistrasi", DataList);
    idpeg = rs.getString(1) ;
    address = "ViewPegawai.jsp";
    return address;
    }

    can somebody help me please?? :'(


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: The record from database can't be retrieved

    Thread moved out of 'What's wrong with my code', and for future reference please wrap code in the code tags.

    Read the API for ResultSet, especially the next() method. If it returns false (eg the cursor is positioned after the last row), any attempt to get a value will throw an SQLException. In your case, you loop over the set, then try to call getString on the ResultSet after it has returned false (eg the cursor is after the last row)

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    20
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: The record from database can't be retrieved

    Hi, the result pointer is pointing to "after last record " after executing the while(rs.next()). But you are calling the idpeg = rs.getString(1) after while loop. There is no record in result set at idpeg = rs.getString(1) . That's why it raising SqlException.

Similar Threads

  1. Trying to out.println of random selected record
    By Walters in forum What's Wrong With My Code?
    Replies: 17
    Last Post: November 13th, 2012, 03:44 PM
  2. How I record sound using MIDI?
    By waseempki in forum Java SE APIs
    Replies: 4
    Last Post: September 16th, 2011, 02:16 PM
  3. Deleting record from database HELP! :(
    By shando1992 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 2nd, 2011, 12:36 AM
  4. how to delete record from checking checkbox value.
    By -_- in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: March 12th, 2010, 07:09 AM
  5. Jsp code which will enable to view a single row from the Database
    By hundu in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: July 5th, 2009, 07:56 AM