是否可以使用 Vert.x JDBCClient 对象执行多个 SQL 插入/更新?
提前致谢。
最佳答案
使用 Vert.x 3.3,您将获得批处理支持,因此您可以执行批量更新:
List<String> batch = new ArrayList<>();
batch.add("INSERT INTO emp (NAME) VALUES ('JOE')");
batch.add("INSERT INTO emp (NAME) VALUES ('JANE')");
connection.batch(batch, res -> {
if (res.succeeded()) {
List<Integer> result = res.result();
} else {
// Failed!
}
});
或者,如果您想重用准备好的语句:
List<JsonArray> batch = new ArrayList<>();
batch.add(new JsonArray().add("joe"));
batch.add(new JsonArray().add("jane"));
connection.batchWithParams("INSERT INTO emp (name) VALUES (?)", batch, res -> {
if (res.succeeded()) {
List<Integer> result = res.result();
} else {
// Failed!
}
});
关于java - 垂直x。在一次调用 update() 中执行多次插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37941464/