How to check if ResultSet has null value?

Discussion in 'Java' started by leni, Feb 10, 2005.

  1. leni

    leni Guest

    Hello,

    I need help, please!
    I have a following code:
    PreparedStatement pstmt = con.prepareStatement(
    "SELECT * FROM MEETINGS WHERE LOGIN = ?");
    pstmt.setRef(1, login);
    ResultSet rs2 = pstmt.executeQuery();
    I want to get all rows from table MEETINGS which represents user's
    meetings. But not for every login (user) there are meetings in the
    table, so ResultSet in this case should have "null" value... How to
    check if ResultsSet retunes null value (no rows in the table)?

    Than you in advance,
    Paulina
     
    leni, Feb 10, 2005
    #1
    1. Advertising

  2. leni wrote:
    > Hello,
    >
    > I need help, please!
    > I have a following code:
    > PreparedStatement pstmt = con.prepareStatement(
    > "SELECT * FROM MEETINGS WHERE LOGIN = ?");
    > pstmt.setRef(1, login);
    > ResultSet rs2 = pstmt.executeQuery();
    > I want to get all rows from table MEETINGS which represents user's
    > meetings. But not for every login (user) there are meetings in the
    > table, so ResultSet in this case should have "null" value... How to
    > check if ResultsSet retunes null value (no rows in the table)?
    >
    > Than you in advance,
    > Paulina


    // fetch data into resultset
    // ...

    if (!resultset.hasNext()) {
    // query returned zero rows
    }


    --
    Regards,

    Karsten
     
    Karsten Baumgarten, Feb 10, 2005
    #2
    1. Advertising

  3. It is resultset.next(), not resultset.hasNext().

    --
    Regards,

    Karsten
     
    Karsten Baumgarten, Feb 10, 2005
    #3
  4. leni

    Tony Morris Guest

    "leni" <> wrote in message
    news:...
    > Hello,
    >
    > I need help, please!
    > I have a following code:
    > PreparedStatement pstmt = con.prepareStatement(
    > "SELECT * FROM MEETINGS WHERE LOGIN = ?");
    > pstmt.setRef(1, login);
    > ResultSet rs2 = pstmt.executeQuery();
    > I want to get all rows from table MEETINGS which represents user's
    > meetings. But not for every login (user) there are meetings in the
    > table, so ResultSet in this case should have "null" value... How to
    > check if ResultsSet retunes null value (no rows in the table)?
    >
    > Than you in advance,
    > Paulina


    boolean hasRows == rs.next();
    The API Specification is your friend.

    --
    Tony Morris
    http://xdweb.net/~dibblego/
     
    Tony Morris, Feb 10, 2005
    #4
  5. In article <>,
    (leni) wrote:

    > Hello,
    >
    > I need help, please!
    > I have a following code:
    > PreparedStatement pstmt = con.prepareStatement(
    > "SELECT * FROM MEETINGS WHERE LOGIN = ?");
    > pstmt.setRef(1, login);
    > ResultSet rs2 = pstmt.executeQuery();
    > I want to get all rows from table MEETINGS which represents user's
    > meetings. But not for every login (user) there are meetings in the
    > table, so ResultSet in this case should have "null" value... How to
    > check if ResultsSet retunes null value (no rows in the table)?


    I don't understand your last sentence: Do you want to know if
    resultSet.next() is false, or are you asking for meetings WHERE
    LOGIN IS NULL?

    --
    John
    jmatthews at wright dot edu
    www dot wright dot edu/~john.matthews/
     
    John B. Matthews, Feb 10, 2005
    #5
  6. leni

    Keir Bowden Guest

    > I need help, please!

    > I have a following code:
    > PreparedStatement pstmt = con.prepareStatement(
    > "SELECT * FROM MEETINGS WHERE LOGIN = ?");
    > pstmt.setRef(1, login);
    > ResultSet rs2 = pstmt.executeQuery();
    > I want to get all rows from table MEETINGS which represents user's
    > meetings. But not for every login (user) there are meetings in the
    > table, so ResultSet in this case should have "null" value... How to
    > check if ResultsSet retunes null value (no rows in the table)?



    If there are no rows in the ResultSet, then next() will return false. Of course this also applies if you have traversed all the rows in the ResultSet by repeated calls to next().


    --
    *Keir Bowden*
    *Iris Financial*
    9^th Floor 12 Arthur Street, London, EC4R 9AB

    Phone: +44 (0) 20 7397 0400
    Direct: +44 (0) 20 7397 0466
    Fax: +44 (0) 20 7397 0401

    www.irisfinancial.com <3D%22http://www.irisfinancial.com%22>

    /The information in this e-mail is confidential and may be legally
    privileged. It is intended solely for the addressee. If you are not the
    intended recipient please delete and do not disclose to another person
    or use, copy or forward all or any of it in any form. Any views
    expressed in this message are those of the individual sender, except
    where the sender specifically states them to be the views of Iris
    Financial Engineering Holdings Limited./
     
    Keir Bowden, Feb 11, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ashutosh

    resultSet is null

    ashutosh, Jun 7, 2005, in forum: Java
    Replies:
    2
    Views:
    6,596
    Malte
    Jun 7, 2005
  2. Replies:
    5
    Views:
    26,941
    Mike Schilling
    Mar 29, 2006
  3. Replies:
    1
    Views:
    1,705
    Bjorn Abelli
    Apr 24, 2006
  4. G Fernandes
    Replies:
    9
    Views:
    608
    DHOLLINGSWORTH2
    Feb 27, 2005
  5. Mike
    Replies:
    12
    Views:
    730
    Daniel Pitts
    Sep 26, 2008
Loading...

Share This Page