Re: JAVA ResultSet Problem?

From: Chris (chris2k01_at_hotmail.com)
Date: 02/28/04


Date: Sat, 28 Feb 2004 04:13:05 GMT


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

GianpieroP wrote:

> ResultSet rs=course.showStudent();
> boolean bEmpty = true;
> while(rs.next()) {
> bEmpty = false;
> out.println(rs.getString("name"));
> }
>
> if (bEmpty)
> out.println("Sad course! There are no students!");
>
> Best regards,
> GianpieroP

Hey,
If you need to know this at the beginning rather than the end:

ResultSet rs = course.showStudent();
if (!rs.isBeforeFirst()) {
        System.out.println("No students");
}
while (rs.next()) {
        ...
}

NOTE: This is untested (based on the JavaDoc specification that
isBeforeFirst() returns, and I quote, "true if the cursor is before
the first row; false if the cursor is at any other position or the
result set contains no rows".

- --
Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQFAP+sjnwjA8LryK2IRApg+AJ94GM3CjVUQXnTFCXG8UiYXUJpsnQCdFF0N
uTshC5VCpKcEvwUkIhWZ0n8=
=YNQo
-----END PGP SIGNATURE-----