本文整理汇总了Java中io.vertx.ext.sql.SQLConnection.update方法的典型用法代码示例。如果您正苦于以下问题:Java SQLConnection.update方法的具体用法?Java SQLConnection.update怎么用?Java SQLConnection.update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.ext.sql.SQLConnection
的用法示例。
在下文中一共展示了SQLConnection.update方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mutate
import io.vertx.ext.sql.SQLConnection; //导入方法依赖的package包/类
/**
* send a query to update within a transaction
* @param conn - connection - see startTx
* @param sql - the sql to run
* @param replyHandler
* Example:
* postgresClient.startTx(beginTx -> {
* try {
* postgresClient.mutate(beginTx, sql, reply -> {...
*/
@SuppressWarnings("unchecked")
public void mutate(Object conn, String sql, Handler<AsyncResult<String>> replyHandler){
SQLConnection sqlConnection = ((Future<SQLConnection>) conn).result();
try {
sqlConnection.update(sql, query -> {
if (query.failed()) {
replyHandler.handle(Future.failedFuture(query.cause()));
} else {
replyHandler.handle(Future.succeededFuture(query.result().toString()));
}
});
} catch (Exception e) {
log.error(e.getMessage(), e);
replyHandler.handle(Future.failedFuture(e));
}
}
示例2: testUpdate
import io.vertx.ext.sql.SQLConnection; //导入方法依赖的package包/类
@Test
public void testUpdate() {
SQLConnection conn = connection();
String sql = "UPDATE update_table SET fname='jane' WHERE id = 1";
conn.update(sql, onSuccess(updated -> {
assertUpdate(updated, 1);
conn.query("SELECT fname FROM update_table WHERE id = 1", onSuccess(resultSet -> {
assertNotNull(resultSet);
assertEquals(1, resultSet.getResults().size());
assertEquals("jane", resultSet.getResults().get(0).getString(0));
testComplete();
}));
}));
await();
}
示例3: testUpdateNoMatch
import io.vertx.ext.sql.SQLConnection; //导入方法依赖的package包/类
@Test
public void testUpdateNoMatch() {
SQLConnection conn = connection();
String sql = "UPDATE update_table SET fname='jane' WHERE id = -231";
conn.update(sql, onSuccess(result -> {
assertUpdate(result, 0);
testComplete();
}));
await();
}
示例4: example4
import io.vertx.ext.sql.SQLConnection; //导入方法依赖的package包/类
public void example4(SQLConnection connection) {
connection.update("INSERT INTO PEOPLE VALUES (null, 'john', 'smith', 9)", res -> {
if (res.succeeded()) {
UpdateResult result = res.result();
System.out.println("Updated no. of rows: " + result.getUpdated());
System.out.println("Generated keys: " + result.getKeys());
} else {
// Failed!
}
});
}