本文整理了Java中io.vertx.ext.sql.SQLConnection.query()
方法的一些代码示例,展示了SQLConnection.query()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SQLConnection.query()
方法的具体详情如下:
包路径:io.vertx.ext.sql.SQLConnection
类名称:SQLConnection
方法名:query
暂无
代码示例来源:origin: vert-x3/vertx-examples
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());
});
}
代码示例来源:origin: vert-x3/vertx-examples
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());
});
}
代码示例来源:origin: vert-x3/vertx-examples
connection.execute("insert into test values(1, 'Hello')", insert -> {
connection.query("select * from test", rs -> {
results.addAll(rs.result().getResults().stream().map(JsonArray::encode).collect(Collectors.toList()));
代码示例来源:origin: vert-x3/vertx-examples
private void handleListProducts(RoutingContext routingContext) {
HttpServerResponse response = routingContext.response();
SQLConnection conn = routingContext.get("conn");
conn.query("SELECT id, name, price, weight FROM products", query -> {
if (query.failed()) {
sendError(500, response);
} else {
JsonArray arr = new JsonArray();
query.result().getRows().forEach(arr::add);
routingContext.response().putHeader("content-type", "application/json").end(arr.encode());
}
});
}
代码示例来源:origin: vert-x3/vertx-examples
connection.query("select * from test", rs -> {
for (JsonArray line : rs.result().getResults()) {
System.out.println(line.encode());
代码示例来源: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 <code>SELECT</code> statement which returns the results of the query.
* @param sql the SQL to execute. For example <code>SELECT * FROM table ...</code>.
* @param resultHandler the handler which is called once the operation completes. It will return a <code>ResultSet</code>.
* @return
*/
public io.vertx.rxjava.ext.sql.SQLConnection query(String sql, Handler<AsyncResult<ResultSet>> resultHandler) {
delegate.query(sql, resultHandler);
return this;
}
代码示例来源:origin: io.vertx/vertx-lang-groovy
public static io.vertx.ext.sql.SQLConnection query(io.vertx.ext.sql.SQLConnection j_receiver, java.lang.String sql, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) {
io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.query(sql,
resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.sql.ResultSet>>() {
public void handle(io.vertx.core.AsyncResult<io.vertx.ext.sql.ResultSet> ar) {
resultHandler.handle(ar.map(event -> event != null ? io.vertx.core.impl.ConversionHelper.fromJsonObject(event.toJson()) : null));
}
} : null));
return j_receiver;
}
public static io.vertx.ext.sql.SQLConnection queryWithParams(io.vertx.ext.sql.SQLConnection j_receiver, java.lang.String sql, java.util.List<Object> params, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) {
代码示例来源:origin: io.vertx/vertx-jdbc-client
@Override
public SQLConnection query(String sql, Handler<AsyncResult<ResultSet>> resultHandler) {
delegate.query(sql, resultHandler);
return this;
}
代码示例来源:origin: io.vertx/vertx-mysql-postgresql-client-jasync
@Test
public void testUnhandledExceptionInHandlerResultSet(TestContext testContext) {
this.<ResultSet>testUnhandledExceptionInHandler(testContext, (sqlConnection, handler) -> {
sqlConnection.query("SELECT name FROM test_table", handler);
});
}
代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client
@Test
public void testUnhandledExceptionInHandlerResultSet(TestContext testContext) {
this.<ResultSet>testUnhandledExceptionInHandler(testContext, (sqlConnection, handler) -> {
sqlConnection.query("SELECT name FROM test_table", handler);
});
}
代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client
@Test
public void testUnhandledExceptionInHandlerResultSet(TestContext testContext) {
this.<ResultSet>testUnhandledExceptionInHandler(testContext, (sqlConnection, handler) -> {
sqlConnection.query("SELECT name FROM test_table", handler);
});
}
代码示例来源:origin: io.vertx/vertx-jdbc-client
@Test
public void testInvalidSelect() {
// Suppress log output so this test doesn't look to fail
setLogLevel(AbstractJDBCAction.class.getName(), Level.SEVERE);
String sql = "SELECT FROM WHERE FOO BAR";
connection().query(sql, onFailure(t -> {
assertNotNull(t);
testComplete();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-jdbc-client
@Test
public void testBlob() {
String sql = "SELECT b FROM blob_table";
connection().query(sql, onSuccess(resultSet -> {
assertNotNull(resultSet);
assertEquals(1, resultSet.getResults().size());
assertNotNull(resultSet.getResults().get(0).getBinary(0));
testComplete();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-jdbc-client
@Test
public void testArray() {
String sql = "SELECT a FROM blob_table";
connection().query(sql, onSuccess(resultSet -> {
assertNotNull(resultSet);
assertEquals(1, resultSet.getResults().size());
assertNotNull(resultSet.getResults().get(0).getJsonArray(0));
testComplete();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-jdbc-client
@Test
public void testClob() {
String sql = "SELECT c FROM blob_table";
connection().query(sql, onSuccess(resultSet -> {
assertNotNull(resultSet);
assertEquals(1, resultSet.getResults().size());
assertNotNull(resultSet.getResults().get(0).getString(0));
testComplete();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-jdbc-client
@Test
public void testCustom() {
String sql = "SELECT u FROM t";
connection().query(sql, onSuccess(resultSet -> {
assertNotNull(resultSet);
assertEquals(1, resultSet.getResults().size());
// we expect a String since UUID will be converted with the fallback mode
assertNotNull(resultSet.getResults().get(0).getString(0));
testComplete();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-jdbc-client
@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();
}
代码示例来源:origin: io.vertx/vertx-jdbc-client
@Test
public void testCloseThenQuery() throws Exception {
client.getConnection(onSuccess(conn -> {
conn.close(onSuccess(v -> {
conn.query("SELECT 1 FROM select_table", onFailure(t -> {
assertNotNull(t);
testComplete();
}));
}));
}));
await();
}
代码示例来源:origin: io.vertx/vertx-jdbc-client
@Test
public void testClose() throws Exception {
client.getConnection(onSuccess(conn -> {
conn.query("SELECT 1 FROM select_table", onSuccess(results -> {
assertNotNull(results);
conn.close(onSuccess(v -> {
testComplete();
}));
}));
}));
await();
}
内容来源于网络,如有侵权,请联系作者删除!