code: int getSize(ResultSet rs) {
      try {
        if (rs.getType() == ResultSet.TYPE_FORWARD_ONLY) {
          return -1;
        }
  
        rs.last();
        int total = rs.getRow();
        rs.beforeFirst();
        return total;
      } catch (SQLException | AbstractMethodError sqle) {
        return -1;
      }
    }
docs: Try to obtain the current size of the specified {@link ResultSet} by
  jumping to the last row and getting the row number.
  
  @param rs the {@link ResultSet} to get the size for
  @return the size, or -1 if it could not be obtained