コード例 #1
0
ファイル: GridRowSet.java プロジェクト: aforino/h2gis
  @Override
  public void reset() throws SQLException {
    cellI = 0;
    cellJ = 0;
    firstRow = false;
    // We compute the extend according the first input value
    if (isTable) {
      Statement statement = connection.createStatement();
      ResultSet rs =
          statement.executeQuery(
              "select ST_Extent("
                  + getFirstGeometryField(tableName, connection)
                  + ")  from "
                  + tableName);
      try {
        rs.next();
        Geometry geomExtend = (Geometry) rs.getObject(1);
        if (geomExtend == null) {
          throw new SQLException("The envelope cannot be null.");
        } else {
          envelope = geomExtend.getEnvelopeInternal();
          initParameters();
        }

      } finally {
        rs.close();
      }
    } else {
      if (envelope == null) {
        throw new SQLException("The input geometry used to compute the grid cannot be null.");
      } else {
        initParameters();
      }
    }
  }
コード例 #2
0
  public void testSerialize() throws IOException, ClassNotFoundException {

    SparseDoubleMatrix2D matrix2D =
        new SparseDoubleMatrix2D(
            new double[][] {
              new double[] {1, 2, 3}, new double[] {4, 5, 6}, new double[] {7, 8, 9}
            });
    System.out.println(String.format("matrix2D: %s", matrix2D));
    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
    } catch (Exception ex) {
      System.err.println("Could not initiate JDBC driver.");
      ex.printStackTrace();
    }

    try {
      Connection conn =
          DriverManager.getConnection(
              "jdbc:mysql://localhost:3306/wittcarl_recurrence_plot_clustering?user=root&password=mysql");
      PreparedStatement preps =
          conn.prepareStatement(
              "INSERT INTO `wittcarl_recurrence_plot_clustering`.`blob` (`id`, `signature`) VALUES (null, ?);");
      preps.setObject(1, matrix2D);
      preps.execute();

      PreparedStatement get = conn.prepareStatement("SELECT id, signature FROM `blob` WHERE id=3");
      ResultSet resultSet = get.executeQuery();
      resultSet.next();
      int id = resultSet.getInt(1);

      InputStream is = resultSet.getBlob(2).getBinaryStream();
      ObjectInputStream oip = new ObjectInputStream(is);
      Object object = oip.readObject();
      String className = object.getClass().getName();
      oip.close();
      is.close();
      resultSet.close();

      // de-serialize list a java object from a given objectID
      SparseDoubleMatrix2D restored = (SparseDoubleMatrix2D) object;

      System.out.println(String.format("id: %s", id));
      System.out.println(String.format("restored: %s", restored));
      conn.close();

    } catch (SQLException ex) {
      // handle any errors
      System.out.println("SQLException: " + ex.getMessage());
      System.out.println("SQLState: " + ex.getSQLState());
      System.out.println("VendorError: " + ex.getErrorCode());
    }
  }