当前位置: 首页>>代码示例>>Java>>正文


Java JDBCClient.getConnection方法代码示例

本文整理汇总了Java中io.vertx.ext.jdbc.JDBCClient.getConnection方法的典型用法代码示例。如果您正苦于以下问题:Java JDBCClient.getConnection方法的具体用法?Java JDBCClient.getConnection怎么用?Java JDBCClient.getConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.vertx.ext.jdbc.JDBCClient的用法示例。


在下文中一共展示了JDBCClient.getConnection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: WikiDatabaseServiceImpl

import io.vertx.ext.jdbc.JDBCClient; //导入方法依赖的package包/类
WikiDatabaseServiceImpl(JDBCClient dbClient, HashMap<SqlQuery, String> sqlQueries, Handler<AsyncResult<WikiDatabaseService>> readyHandler) {
  this.dbClient = dbClient;
  this.sqlQueries = sqlQueries;

  dbClient.getConnection(ar -> {
    if (ar.failed()) {
      LOGGER.error("Could not open a database connection", ar.cause());
      readyHandler.handle(Future.failedFuture(ar.cause()));
    } else {
      SQLConnection connection = ar.result();
      connection.execute(sqlQueries.get(SqlQuery.CREATE_PAGES_TABLE), create -> {
        connection.close();
        if (create.failed()) {
          LOGGER.error("Database preparation error", create.cause());
          readyHandler.handle(Future.failedFuture(create.cause()));
        } else {
          readyHandler.handle(Future.succeededFuture(this));
        }
      });
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:23,代码来源:WikiDatabaseServiceImpl.java

示例2: testStockTradesPersisted

import io.vertx.ext.jdbc.JDBCClient; //导入方法依赖的package包/类
@Test
public void testStockTradesPersisted(TestContext context) throws ClassNotFoundException {
    Async async = context.async();
    JsonObject jdbcConfig = new JsonObject(config.getObject("jdbc").render(ConfigRenderOptions.concise()));
    JDBCClient jdbc = JDBCClient.createNonShared(vertx, jdbcConfig);
    Class.forName(jdbcConfig.getString("driverclass"));

    jdbc.getConnection(ar -> {
        SQLConnection connection = ar.result();
        if (ar.failed()) {
            context.fail(ar.cause());
        } else {
            connection.query(SELECT_STATEMENT, result -> {
                ResultSet set = result.result();
                List<JsonObject> operations = set.getRows().stream()
                        .map(json -> new JsonObject(json.getString("OPERATION")))
                        .collect(Collectors.toList());
                context.assertTrue(operations.size() >= 3);
                connection.close();
                async.complete();
            });
        }
    });
}
 
开发者ID:docker-production-aws,项目名称:microtrader,代码行数:25,代码来源:AuditVerticleTest.java

示例3: example4

import io.vertx.ext.jdbc.JDBCClient; //导入方法依赖的package包/类
public void example4(JDBCClient client) {

    // Now do stuff with it:

    client.getConnection(res -> {
      if (res.succeeded()) {

        SQLConnection connection = res.result();

        connection.query("SELECT * FROM some_table", res2 -> {
          if (res2.succeeded()) {

            ResultSet rs = res2.result();
            // Do something with results
          }
        });
      } else {
        // Failed to get connection - deal with it
      }
    });

  }
 
开发者ID:vert-x3,项目名称:vertx-jdbc-client,代码行数:23,代码来源:JDBCExamples.java

示例4: test

import io.vertx.ext.jdbc.JDBCClient; //导入方法依赖的package包/类
@Test
public void test() throws InterruptedException {
  JsonObject conf = new JsonObject()
      .put("driverclass", "org.hsqldb.jdbcDriver");

  Record record = JDBCDataSource.createRecord("some-hsql-db",
      new JsonObject().put("url", "jdbc:hsqldb:file:target/dumb-db;shutdown=true"),
      new JsonObject().put("database", "some-raw-data"));

  discovery.publish(record, (r) -> {
  });
  await().until(() -> record.getRegistration() != null);

  AtomicReference<Record> found = new AtomicReference<>();
  discovery.getRecord(new JsonObject().put("name", "some-hsql-db"), ar -> {
    found.set(ar.result());
  });

  await().until(() -> found.get() != null);

  ServiceReference service = discovery.getReferenceWithConfiguration(found.get(), conf);
  JDBCClient client = service.get();
  AtomicBoolean success = new AtomicBoolean();
  client.getConnection(ar -> {
    if (ar.succeeded()) {
      ar.result().close();
    }
    success.set(ar.succeeded());
  });

  await().untilAtomic(success, is(true));
  service.release();
  // Just there to be sure we can call it twice
  service.release();
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:36,代码来源:JDBCDataSourceTest.java


注:本文中的io.vertx.ext.jdbc.JDBCClient.getConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。