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