@Override public void start() throws Exception { JsonObject config = new JsonObject().put("url", "jdbc:hsqldb:mem:test?shutdown=true") .put("driver_class", "org.hsqldb.jdbcDriver"); JDBCClient jdbc = JDBCClient.createShared(vertx, config); // Connect to the database jdbc.rxGetConnection().flatMap(conn -> { // Now chain some statements using flatmap composition Single<ResultSet> resa = conn.rxUpdate("CREATE TABLE test(col VARCHAR(20))") .flatMap(result -> conn.rxUpdate("INSERT INTO test (col) VALUES ('val1')")) .flatMap(result -> conn.rxUpdate("INSERT INTO test (col) VALUES ('val2')")) .flatMap(result -> conn.rxQuery("SELECT * FROM test")); return resa.doAfterTerminate(conn::close); }).subscribe(resultSet -> { // Subscribe to the final result System.out.println("Results : " + resultSet.getRows()); }, err -> { System.out.println("Database problem"); err.printStackTrace(); }); } }
@Override public void start() throws Exception { JsonObject config = new JsonObject().put("url", "jdbc:hsqldb:mem:test?shutdown=true") .put("driver_class", "org.hsqldb.jdbcDriver"); JDBCClient jdbc = JDBCClient.createShared(vertx, config); jdbc .rxGetConnection() // Connect to the database .flatMapObservable(conn -> { // With the connection... return conn.rxUpdate("CREATE TABLE test(col VARCHAR(20))") // ...create test table .flatMap(result -> conn.rxUpdate("INSERT INTO test (col) VALUES ('val1')")) // ...insert a row .flatMap(result -> conn.rxUpdate("INSERT INTO test (col) VALUES ('val2')")) // ...another one .flatMap(result -> conn.rxQueryStream("SELECT * FROM test")) // ...get values stream .flatMapObservable(sqlRowStream -> { return sqlRowStream.toObservable() // Transform the stream into an Observable... .doOnTerminate(conn::close); // ...and close the connection when the stream is fully read or an error occurs }); }).subscribe(row -> System.out.println("Row : " + row.encode())); } }
"datetime TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL)"; JDBCClient client = JDBCClient.createShared(vertx, config);