public void testWriteDB() throws SQLException { 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"); TimeSeriesGenerator tsg = new TimeSeriesGenerator(1, 1000, "lorenz"); double[][] trajectory = tsg.lorenz_standard[0]; DRQA drqa = new DRQA(trajectory, trajectory, 0.05); drqa.computeRQA(2, 2, 2); drqa.writeResultDB( "IN_MEMORY", "lorenz", DRQA.EmbeddingMethod.ORIGINAL_TRAJECTORY.ordinal(), 3, -1, trajectory[0].length, DRQA.LMinMethod.L_MIN_FIX.ordinal(), 2, 0, conn); } catch (SQLException ex) { System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); } }
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()); } }