8.2.3. SQL クエリーの実行
ここでは、JDBC クライアントでクエリーを実行する方法を説明します。
8.2.3.1. 単発のクエリーの実行 リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
以下の例は、Eclipse Vert.x 3.x で接続を管理せずにクエリーを実行する方法を示しています。
// 3.x
client.query("SELECT * FROM user WHERE emp_id > ?", new JsonArray().add(1000), res -> {
if (res.succeeded()) {
ResultSet rs = res2.result();
// You can use these results in your application
}
});
以下の例は、Eclipse Vert.x 4 で接続を管理せずにクエリーを実行する方法を示しています。
// 4.x
pool
.preparedQuery("SELECT * FROM user WHERE emp_id > ?")
// the emp id to look up
.execute(Tuple.of(1000))
.onSuccess(rows -> {
for (Row row : rows) {
System.out.println(row.getString("FIRST_NAME"));
}
});