8.2.3.2. 管理接続でのクエリーの実行
以下の例は、Eclipse Vert.x 4 で管理された接続でクエリーを実行する方法を示しています。
pool .getConnection() .onFailure(e -> { // Failed to get a connection }) .onSuccess(conn -> { conn .query("SELECT * FROM user") .execute() .onFailure(e -> { // Handle the failure // Important, do not forget to return the connection conn.close(); }) .onSuccess(rows -> { for (Row row : rows) { System.out.println(row.getString("FIRST_NAME")); } // Important, do not forget to return the connection conn.close(); }); });
pool
.getConnection()
.onFailure(e -> {
// Failed to get a connection
})
.onSuccess(conn -> {
conn
.query("SELECT * FROM user")
.execute()
.onFailure(e -> {
// Handle the failure
// Important, do not forget to return the connection
conn.close();
})
.onSuccess(rows -> {
for (Row row : rows) {
System.out.println(row.getString("FIRST_NAME"));
}
// Important, do not forget to return the connection
conn.close();
});
});