code: public static Envelope getTableEnvelope(Connection connection, TableLocation location, String geometryField)
              throws SQLException {
          if(geometryField==null || geometryField.isEmpty()) {
              List<String> geometryFields = getGeometryFields(connection, location);
              if(geometryFields.isEmpty()) {
                  throw new SQLException("The table "+location+" does not contain a Geometry field, then the extent " +
                          "cannot be computed");
              }
              geometryField = geometryFields.get(0);
          }
          ResultSet rs = connection.createStatement().executeQuery("SELECT ST_Extent("+
                  TableLocation.quoteIdentifier(geometryField)+") ext FROM "+location);
          if(rs.next()) {
              // Todo under postgis it is a BOX type
              return ((Geometry)rs.getObject(1)).getEnvelopeInternal();
          }
          throw new SQLException("Unable to get the table extent it may be empty");
      }
docs: Merge the bounding box of all geometries inside the provided table.
  
  @param connection Active connection (not closed by this function)
  @param location Location of the table
  @param geometryField Geometry field or empty string (take the first geometry field)
  
  @return Envelope of the table
  
  @throws SQLException If the table not exists, empty or does not contain a geometry field.