Results 1 to 8 of 8

Thread: help needed

  1. #1
    Join Date
    Jan 2010
    Posts
    72
    Rep Power
    0

    Default help needed

    hi i am having logical error in this code

    for(i=0;i<10;i++){
    %>
    <br><br>
    <select name="<%=i%>">
    <option></option>
    <%
    while(me.next())
    {
    %>
    <option><%=me.getString("pname")%> - <%=me.getString("aname")%>
    </option>
    <%
    }
    %>
    </select>
    <%
    me.beforeFirst();
    }

    i am returning a resultset from bean which is saving in 'me'
    to get multiple drop down list i used for loop. after each while the resulset cursor will be pointing to the last row so i used me.beforeFirst() to get the cursor back to the first row

    Now what is happening here is if i insert 'me.beforeFirst()' then 'for loop' is running only once

    please explain

  2. #2
    Aseem is offline Senior Member
    Join Date
    Mar 2009
    Location
    USA
    Posts
    127
    Rep Power
    0

    Default

    Are you trying to get 10 names in multi selection box but you are getting only one. is that what you mean?

  3. #3
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Don't do any of this. Get your database results in a servlet or helper class and set the collection in the request scope. Then your JSP simply reads the collection and displays it using EL.

  4. #4
    Join Date
    Jan 2010
    Posts
    72
    Rep Power
    0

    Default

    @r035198x
    thanx a lot.....
    but can u explain why this is not working
    @Aseem
    ya if i am inserting "me.beforeFirst()"

  5. #5
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by silversurfer2in View Post
    @r035198x
    thanx a lot.....
    but can u explain why this is not working
    Read the API specs for the beforeFirst method before using it.
    After your first calls to rs.next are done, the result set now contains no rows and beforeFirst on it is no-op.

  6. #6
    Join Date
    Jan 2010
    Posts
    72
    Rep Power
    0

    Default

    Quote Originally Posted by r035198x View Post
    Read the API specs for the beforeFirst method before using it.
    After your first calls to rs.next are done, the result set now contains no rows and beforeFirst on it is no-op.

    public boolean first()
    throws SQLException

    Moves the cursor to the first row in this ResultSet object.

    Returns:
    true if the cursor is on a valid row; false if there are no rows in the result set


    public void beforeFirst()
    throws SQLException

    Moves the cursor to the front of this ResultSet object, just before the first row. This method has no effect if the result set contains no rows.


    which one should be used in this case.....since both of them are bringing the cursor from the last row to the first row

  7. #7
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    I just explained that the specs say This method has no effect if the result set contains no rows. Dump your approach and use the approach I suggested above.

  8. #8
    Join Date
    Jan 2010
    Posts
    72
    Rep Power
    0

Similar Threads

  1. Help Needed!
    By Lyricid in forum New To Java
    Replies: 8
    Last Post: 12-09-2009, 09:34 PM
  2. Help needed
    By harshalsakpal in forum CLDC and MIDP
    Replies: 0
    Last Post: 02-17-2009, 03:53 PM
  3. help needed
    By amarchandar in forum New To Java
    Replies: 3
    Last Post: 02-17-2009, 01:59 PM
  4. Help needed.
    By necro-1000 in forum AWT / Swing
    Replies: 2
    Last Post: 01-12-2008, 11:37 AM
  5. Help Needed
    By pks in forum New To Java
    Replies: 1
    Last Post: 01-09-2008, 12:07 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
  •