#1
  1. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Posts
    14
    Rep Power
    0

    Number of rows in the select statement


    I am doing a select select statement through JSP. I wan't to give number of rows in the result...

    For eg..

    String s1 = "SELECT id, f_name,l_name FROM login WHERE username = '"+ username +" '";
    I want to display the number of rows returned....

    How do I do that....

    I tried...
    int rowsUpdated1 = theStatement.executeSelect(s1);

    got the following error....

    Can't convert java.sql.ResultSet to int.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    new york
    Posts
    84
    Rep Power
    13
    i don't know of any member functions to do this, but this should work:
    Code:
    public int getNumRows(ResultSet rs) {
        int numRows = 0;     
        while(rs.next()) {
            numRows++;
        }
        return numRows;
    }
  4. #3
  5. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Ya, I don't see anything either.

    One thing you could do is add something like "count(*) as rsSize" to your sql, then get the value out of the ResultSet. This is probably faster than counting the rows.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    new york
    Posts
    84
    Rep Power
    13

IMN logo majestic logo threadwatch logo seochat tools logo