code: public static boolean isSRIDValid(int srid, Connection connection) throws SQLException {
          PreparedStatement ps = null;
          ResultSet rs = null;
          String queryCheck = "SELECT count(SRID) from PUBLIC.SPATIAL_REF_SYS WHERE SRID = ?";
          try {
              ps = connection.prepareStatement(queryCheck);
              ps.setInt(1, srid);
              rs = ps.executeQuery();
              if (rs.next()) {
                  return rs.getInt(1) != 0;
              }
          } finally {
              if (rs != null) {
                  rs.close();
              }
              if (ps != null) {
                  ps.close();
              }
          }
          return false;
      }
docs: This method checks if a SRID value is valid according a list of SRID's
  avalaible on spatial_ref table of the datababase.
  
  @param srid
  @param connection
  @return
  @throws java.sql.SQLException