code: public static Envelope getResultSetEnvelope(ResultSet resultSet, String fieldName) throws SQLException {
          Envelope aggregatedEnvelope = null;
          while (resultSet.next()) {
              Geometry geom = (Geometry) resultSet.getObject(fieldName);
              if (aggregatedEnvelope != null) {
                  aggregatedEnvelope.expandToInclude(geom.getEnvelopeInternal());
              } else {
                  aggregatedEnvelope = geom.getEnvelopeInternal();
              }
          }
          return aggregatedEnvelope;
      }
docs: Compute the full extend of a ResultSet using a specified geometry field.
  If the ResultSet does not contain this geometry field throw an exception
  
  @param resultSet ResultSet to analyse
  @param fieldName Field to analyse
  
  @return The full extend of the field in the ResultSet
  
  @throws SQLException