本文整理汇总了Java中io.vertx.ext.sql.SQLConnection.query方法的典型用法代码示例。如果您正苦于以下问题:Java SQLConnection.query方法的具体用法?Java SQLConnection.query怎么用?Java SQLConnection.query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.ext.sql.SQLConnection
的用法示例。
在下文中一共展示了SQLConnection.query方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSomeDataIfNone
import io.vertx.ext.sql.SQLConnection; //导入方法依赖的package包/类
private Future<SQLConnection> createSomeDataIfNone(SQLConnection connection) {
Future<SQLConnection> future = Future.future();
connection.query("SELECT * FROM Articles", select -> {
if (select.failed()) {
future.fail(select.cause());
} else {
if (select.result().getResults().isEmpty()) {
Article article1 = new Article("Fallacies of distributed computing",
"https://en.wikipedia.org/wiki/Fallacies_of_distributed_computing");
Article article2 = new Article("Reactive Manifesto",
"https://www.reactivemanifesto.org/");
Future<Article> insertion1 = insert(connection, article1, false);
Future<Article> insertion2 = insert(connection, article2, false);
CompositeFuture.all(insertion1, insertion2)
.setHandler(r -> future.handle(r.map(connection)));
} else {
future.complete(connection);
}
}
});
return future;
}
示例2: query
import io.vertx.ext.sql.SQLConnection; //导入方法依赖的package包/类
private Future<List<Article>> query(SQLConnection connection) {
Future<List<Article>> future = Future.future();
connection.query("SELECT * FROM articles", result -> {
connection.close();
future.handle(
result.map(rs -> rs.getRows().stream().map(Article::new).collect(Collectors.toList()))
);
}
);
return future;
}
示例3: query
import io.vertx.ext.sql.SQLConnection; //导入方法依赖的package包/类
private void query(SQLConnection conn, String sql, Handler<ResultSet> done) {
conn.query(sql, res -> {
if (res.failed()) {
throw new RuntimeException(res.cause());
}
done.handle(res.result());
});
}
示例4: example2
import io.vertx.ext.sql.SQLConnection; //导入方法依赖的package包/类
public void example2(SQLConnection connection) {
connection.query("SELECT ID, FNAME, LNAME, SHOE_SIZE from PEOPLE", res -> {
if (res.succeeded()) {
// Get the result set
ResultSet resultSet = res.result();
} else {
// Failed!
}
});
}
示例5: testSameContext
import io.vertx.ext.sql.SQLConnection; //导入方法依赖的package包/类
@Test
public void testSameContext() {
Context ctx = vertx.getOrCreateContext();
SQLConnection conn = connection(ctx);
conn.query("SELECT a FROM blob_table", onSuccess(rs -> {
assertSame(Vertx.currentContext(), ctx);
testComplete();
}));
await();
}