How to judge if the resultset having empty rows?

Hi,

I have a problem when processing a resultset.

....

ResultSet rs = null;

rs = statement.executeQuery(SQLstr);

if ( rs != null ) {

//doSomeThingWith the rs

} else {

// warning the user

}

I found that the else clause never been executed even thought the rs get empty set from mysql.

the following is a example when I manually execute the select SQL within mysql:

mysql>select * from tableName where mobile='1383322331';

Empty set (0.01 sec)

[531 byte] By [ioiioia] at [2007-10-3 5:22:15]
# 1

I find a stupid solution:

if ( rs != null ) {

if ( rs.next() ) {

rs.previous();

while ( rs.next()) {

//doSomeThingWithIt

}

} else {

//warning the user

}

}

Any good suggestion?

ioiioia at 2007-7-14 23:29:17 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

boolean hasRows = false;

while (rs.next()){

hasRows = true;

//Do your stuff

}

if (!hasRows ){

//Empty result set

}

//You dont have to test for null result set

LRMKa at 2007-7-14 23:29:17 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
rs == nulldoes not mean that the resultset is empty. It means that the variable rs is referencing no object.
r035198xa at 2007-7-14 23:29:17 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...