io.vertx.ext.sql.SQLConnection.execute()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(162)

本文整理了Java中io.vertx.ext.sql.SQLConnection.execute()方法的一些代码示例,展示了SQLConnection.execute()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SQLConnection.execute()方法的具体详情如下:
包路径:io.vertx.ext.sql.SQLConnection
类名称:SQLConnection
方法名:execute

SQLConnection.execute介绍

[英]Executes the given SQL statement
[中]执行给定的SQL语句

代码示例

代码示例来源:origin: vert-x3/vertx-examples

private void execute(SQLConnection conn, String sql, Handler<Void> done) {
 conn.execute(sql, res -> {
  if (res.failed()) {
   throw new RuntimeException(res.cause());
  }
  done.handle(null);
 });
}

代码示例来源:origin: vert-x3/vertx-examples

private void execute(SQLConnection conn, String sql, Handler<Void> done) {
 conn.execute(sql, res -> {
  if (res.failed()) {
   throw new RuntimeException(res.cause());
  }
  done.handle(null);
 });
}

代码示例来源:origin: vert-x3/vertx-examples

private void setUpInitialData(Handler<Void> done) {
  client.getConnection(res -> {
   if (res.failed()) {
    throw new RuntimeException(res.cause());
   }

   final SQLConnection conn = res.result();

   conn.execute("CREATE TABLE IF NOT EXISTS products(id INT IDENTITY, name VARCHAR(255), price FLOAT, weight INT)", ddl -> {
    if (ddl.failed()) {
     throw new RuntimeException(ddl.cause());
    }

    conn.execute("INSERT INTO products (name, price, weight) VALUES ('Egg Whisk', 3.99, 150), ('Tea Cosy', 5.99, 100), ('Spatula', 1.00, 80)", fixtures -> {
     if (fixtures.failed()) {
      throw new RuntimeException(fixtures.cause());
     }

     done.handle(null);
    });
   });
  });
 }
}

代码示例来源:origin: vert-x3/vertx-examples

connection.execute("create table test(id int primary key, name varchar(255))", res -> {
 if (res.failed()) {
  resultHandler.handle(Future.failedFuture(res.cause()));
 connection.execute("insert into test values(1, 'Hello')", insert -> {

代码示例来源:origin: vert-x3/vertx-examples

connection.execute("create table test(id int primary key, name varchar(255))", res -> {
 if (res.failed()) {
  throw new RuntimeException(res.cause());
 connection.execute("insert into test values(1, 'Hello')", insert -> {

代码示例来源:origin: vert-x3/vertx-examples

connection.execute("create table test(id int primary key, name varchar(255))", create -> {
 if (create.failed()) {
  System.err.println("Cannot create the table");
 connection.execute("insert into test values (1, 'Hello'), (2, 'World')", insert -> {

代码示例来源:origin: vert-x3/vertx-examples

connection.execute("create table test(id int primary key, name varchar(255))", res -> {
 if (res.failed()) {
  throw new RuntimeException(res.cause());
 connection.execute("insert into test values (1, 'Hello'), (2, 'Goodbye'), (3, 'Cya Later')", insert -> {

代码示例来源:origin: vert-x3/vertx-examples

@Override
@Suspendable
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);
 // Get a connection
 try (SQLConnection conn = awaitResult(jdbc::getConnection)) {
  // Create a table
  Void v = awaitResult(h -> conn.execute("CREATE TABLE test(col VARCHAR(20))", h));
  // Insert some stuff
  for (int i = 0; i < 10; i++) {
   int ii = i;
   UpdateResult res = awaitResult(h -> conn.update("INSERT INTO test (col) VALUES ('val" + ii + "')", h));
   System.out.println("Rows updated: " + res.getUpdated());
  }
  // Select the results
  ResultSet res = awaitResult(h -> conn.query("SELECT * FROM test", h));
  System.out.println("Selected " + res.getNumRows() + " results");
  res.getResults().forEach(System.out::println);
 }
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Executes the given SQL statement
 * @param sql the SQL to execute. For example <code>CREATE TABLE IF EXISTS table ...</code>
 * @param resultHandler the handler which is called once this operation completes.
 * @return 
 */
public io.vertx.rxjava.ext.sql.SQLConnection execute(String sql, Handler<AsyncResult<Void>> resultHandler) { 
 delegate.execute(sql, resultHandler);
 return this;
}

代码示例来源:origin: io.vertx/vertx-mysql-postgresql-client-jasync

private void setupAutoIncrementTable(SQLConnection conn, Handler<AsyncResult<Void>> handler) {
 conn.execute("BEGIN",
   ar -> conn.execute("DROP TABLE IF EXISTS test_table",
     ar2 -> conn.execute("CREATE TABLE test_table (id BIGSERIAL, name VARCHAR(255), PRIMARY KEY(id))",
       ar3 -> conn.execute("COMMIT", handler::handle))));
}

代码示例来源:origin: io.vertx/vertx-jdbc-client

@Override
public SQLConnection execute(String sql, Handler<AsyncResult<Void>> resultHandler) {
 delegate.execute(sql, resultHandler);
 return this;
}

代码示例来源:origin: io.vertx/vertx-mysql-postgresql-client-jasync

private void setupTableWithUUIDs(SQLConnection conn, Handler<AsyncResult<Void>> handler) {
  conn.execute("BEGIN",
    ar -> conn.execute("DROP TABLE IF EXISTS test_table",
      ar2 -> conn.execute("CREATE TABLE test_table (some_uuid UUID, name VARCHAR(255))",
        ar3 -> conn.execute("COMMIT", handler::handle))));
 }
}

代码示例来源:origin: io.vertx/vertx-mysql-postgresql-client-jasync

private void setupAutoIncrementTable(SQLConnection conn, Handler<AsyncResult<Void>> handler) {
  conn.execute("BEGIN",
    ar -> conn.execute("DROP TABLE IF EXISTS test_table",
      ar2 -> conn.execute("CREATE TABLE test_table (id BIGINT AUTO_INCREMENT, name VARCHAR(255), PRIMARY KEY(id))",
        ar3 -> conn.execute("COMMIT", handler::handle))));
 }
}

代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client

private void setupTestTable(SQLConnection conn, Supplier<String> idNameValuesSupplier, Handler<AsyncResult<Void>> handler) {
 conn.execute("BEGIN",
  ar -> conn.execute("DROP TABLE IF EXISTS test_table",
   ar2 -> conn.execute(CREATE_TABLE_STATEMENT,
    ar3 -> conn.update("INSERT INTO test_table (id, name) VALUES " + idNameValuesSupplier.get(),
     ar4 -> conn.execute("COMMIT", handler)))));
}

代码示例来源:origin: io.vertx/vertx-mysql-postgresql-client-jasync

private void setupTestTable(SQLConnection conn, Supplier<String> idNameValuesSupplier, Handler<AsyncResult<Void>> handler) {
 conn.execute("BEGIN",
  ar -> conn.execute("DROP TABLE IF EXISTS test_table",
   ar2 -> conn.execute(CREATE_TABLE_STATEMENT,
    ar3 -> conn.update("INSERT INTO test_table (id, name) VALUES " + idNameValuesSupplier.get(),
     ar4 -> conn.execute("COMMIT", handler)))));
}

代码示例来源:origin: io.vertx/vertx-mysql-postgresql-client-jasync

@Override
protected void setSqlModeIfPossible(Handler<Void> handler) {
 conn.execute("set SQL_MODE = 'STRICT_ALL_TABLES'", ar1 -> {
  // INFO: we ignore the result of this call because it is a mysql specific feature and not all versions support it
  // what is means is that we want the sql parser to be strict even if the engine e.g.: myisam does not implement
  // all constraints such as is the date Feb 31 a valid date. By specifying this we will tell for example that the
  // previous date is invalid.
  handler.handle(null);
 });
}

代码示例来源:origin: sczyh30/vertx-blueprint-microservice

@Override
public void initializePersistence(Handler<AsyncResult<Void>> resultHandler) {
 jdbc.getConnection(connHandler(resultHandler, connection -> {
  connection.execute(CREATE_STATEMENT, r -> {
   resultHandler.handle(r);
   connection.close();
  });
 }));
}

代码示例来源:origin: sczyh30/vertx-blueprint-microservice

@Override
public ProductService initializePersistence(Handler<AsyncResult<Void>> resultHandler) {
 client.getConnection(connHandler(resultHandler, connection -> {
  connection.execute(CREATE_STATEMENT, r -> {
   resultHandler.handle(r);
   connection.close();
  });
 }));
 return this;
}

代码示例来源:origin: sczyh30/vertx-blueprint-microservice

@Override
public AccountService initializePersistence(Handler<AsyncResult<Void>> resultHandler) {
 client.getConnection(connHandler(resultHandler, connection -> {
  connection.execute(CREATE_STATEMENT, r -> {
   resultHandler.handle(r);
   connection.close();
  });
 }));
 return this;
}

代码示例来源:origin: sczyh30/vertx-blueprint-microservice

@Override
public OrderService initializePersistence(Handler<AsyncResult<Void>> resultHandler) {
 client.getConnection(connHandler(resultHandler, connection -> {
  connection.execute(CREATE_STATEMENT, r -> {
   resultHandler.handle(r);
   connection.close();
  });
 }));
 return this;
}

相关文章