How to check if ResultSet has null value?

L

leni

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
 
K

Karsten Baumgarten

leni said:
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
}
 
T

Tony Morris

leni said:
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.
 
J

John B. Matthews

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?
 
K

Keir Bowden

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./
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top