本文整理汇总了Java中io.vertx.ext.sql.SQLConnection.updateWithParams方法的典型用法代码示例。如果您正苦于以下问题:Java SQLConnection.updateWithParams方法的具体用法?Java SQLConnection.updateWithParams怎么用?Java SQLConnection.updateWithParams使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.ext.sql.SQLConnection
的用法示例。
在下文中一共展示了SQLConnection.updateWithParams方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: delete
import io.vertx.ext.sql.SQLConnection; //导入方法依赖的package包/类
private Future<Void> delete(SQLConnection connection, String id) {
Future<Void> future = Future.future();
String sql = "DELETE FROM Articles WHERE id = ?";
connection.updateWithParams(sql,
new JsonArray().add(Integer.valueOf(id)),
ar -> {
connection.close();
if (ar.failed()) {
future.fail(ar.cause());
} else {
if (ar.result().getUpdated() == 0) {
future.fail(new NoSuchElementException("Unknown article " + id));
} else {
future.complete();
}
}
}
);
return future;
}
示例2: insert
import io.vertx.ext.sql.SQLConnection; //导入方法依赖的package包/类
private Future<Article> insert(SQLConnection connection, Article article, boolean closeConnection) {
Future<Article> future = Future.future();
String sql = "INSERT INTO Articles (title, url) VALUES (?, ?)";
connection.updateWithParams(sql,
new JsonArray().add(article.getTitle()).add(article.getUrl()),
ar -> {
if (closeConnection) {
connection.close();
}
future.handle(
ar.map(res -> new Article(res.getKeys().getLong(0), article.getTitle(), article.getUrl()))
);
}
);
return future;
}
示例3: update
import io.vertx.ext.sql.SQLConnection; //导入方法依赖的package包/类
private Future<Void> update(SQLConnection connection, String id, Article article) {
Future<Void> future = Future.future();
String sql = "UPDATE articles SET title = ?, url = ? WHERE id = ?";
connection.updateWithParams(sql, new JsonArray().add(article.getTitle()).add(article.getUrl())
.add(Integer.valueOf(id)),
ar -> {
connection.close();
if (ar.failed()) {
future.fail(ar.cause());
} else {
UpdateResult ur = ar.result();
if (ur.getUpdated() == 0) {
future.fail(new NoSuchElementException("No article with id " + id));
} else {
future.complete();
}
}
});
return future;
}
示例4: testUpdateWithParams
import io.vertx.ext.sql.SQLConnection; //导入方法依赖的package包/类
@Test
public void testUpdateWithParams() {
SQLConnection conn = connection();
String sql = "UPDATE update_table SET fname = ? WHERE id = ?";
JsonArray params = new JsonArray().add("bob").add(1);
conn.updateWithParams(sql, params, onSuccess(result -> {
assertUpdate(result, 1);
conn.query("SELECT fname FROM update_table WHERE id = 1", onSuccess(resultSet -> {
assertNotNull(resultSet);
assertEquals(1, resultSet.getResults().size());
assertEquals("bob", resultSet.getResults().get(0).getString(0));
testComplete();
}));
}));
await();
}
示例5: updateWithParams
import io.vertx.ext.sql.SQLConnection; //导入方法依赖的package包/类
private void updateWithParams(SQLConnection conn, String sql, JsonArray params, Handler<Void> done) {
conn.updateWithParams(sql, params, res -> {
if (res.failed()) {
throw new RuntimeException(res.cause());
}
done.handle(null);
});
}
示例6: testInsertUpdateNoIdentity
import io.vertx.ext.sql.SQLConnection; //导入方法依赖的package包/类
/**
* Test that insert and update works in a table without an identity column.
*/
@Test
public void testInsertUpdateNoIdentity() {
SQLConnection conn = connection();
String insertsql = "INSERT INTO insert_tableNoIdentity (id, lname, fname, dob) VALUES (?, ?, ?, ?)";
JsonArray insertparams = new JsonArray().add(1).add("LastName1").addNull().add("2002-02-02");
conn.updateWithParams(insertsql, insertparams, onSuccess(insertResultSet -> {
assertUpdate(insertResultSet, 1);
int insertid = insertResultSet.getKeys().isEmpty() ? 1 : insertResultSet.getKeys().getInteger(0);
conn.queryWithParams("SElECT lname FROM insert_tableNoIdentity WHERE id=?", new JsonArray().add(1), onSuccess(insertQueryResultSet -> {
assertNotNull(insertQueryResultSet);
assertEquals(1, insertQueryResultSet.getResults().size());
assertEquals("LastName1", insertQueryResultSet.getResults().get(0).getValue(0));
System.out.println("testInsertUpdateNoIdentity: insert: " + insertQueryResultSet.getResults().get(0).getValue(0));
// Now test that update works
String updSql = "UPDATE insert_tableNoIdentity SET lname=? WHERE id=?";
JsonArray updParams = new JsonArray().add("LastName2").add(insertid);
conn.updateWithParams(updSql, updParams, onSuccess(updateResultSet -> {
assertUpdate(updateResultSet, 1);
int updateid = updateResultSet.getKeys().isEmpty() ? 1 : updateResultSet.getKeys().getInteger(0);
conn.queryWithParams("SElECT lname FROM insert_tableNoIdentity WHERE id=?", new JsonArray().add(updateid), onSuccess(updateQueryResultSet -> {
assertNotNull(updateQueryResultSet);
assertEquals(1, updateQueryResultSet.getResults().size());
assertEquals("LastName2", updateQueryResultSet.getResults().get(0).getValue(0));
System.out.println("testInsertUpdateNoIdentity: update: " + updateQueryResultSet.getResults().get(0).getValue(0));
testComplete();
}));
}));
}));
}));
await();
}
示例7: example9
import io.vertx.ext.sql.SQLConnection; //导入方法依赖的package包/类
public void example9(JDBCAuth auth, SQLConnection conn) {
String salt = auth.generateSalt();
String hash = auth.computeHash("sausages", salt);
// save to the database
conn.updateWithParams("INSERT INTO user VALUES (?, ?, ?)", new JsonArray().add("tim").add(hash).add(salt), res -> {
if (res.succeeded()) {
// success!
}
});
}
示例8: example11
import io.vertx.ext.sql.SQLConnection; //导入方法依赖的package包/类
public void example11(JDBCAuth auth, SQLConnection conn) {
auth.setNonces(new JsonArray().add("random_hash_1").add("random_hash_1"));
String salt = auth.generateSalt();
// we will pick the second nonce
String hash = auth.computeHash("sausages", salt, 1);
// save to the database
conn.updateWithParams("INSERT INTO user VALUES (?, ?, ?)", new JsonArray().add("tim").add(hash).add(salt), res -> {
if (res.succeeded()) {
// success!
}
});
}
示例9: example5
import io.vertx.ext.sql.SQLConnection; //导入方法依赖的package包/类
public void example5(SQLConnection connection) {
String update = "UPDATE PEOPLE SET SHOE_SIZE = 10 WHERE LNAME=?";
JsonArray params = new JsonArray().add("Fox");
connection.updateWithParams(update, params, res -> {
if (res.succeeded()) {
UpdateResult updateResult = res.result();
System.out.println("No. of rows updated: " + updateResult.getUpdated());
} else {
// Failed!
}
});
}