import io.reactiverse.pgclient.PgClient;
import io.reactiverse.pgclient.PgConnectOptions;
import io.reactiverse.pgclient.PgConnection;
import io.reactiverse.pgclient.PgRowSet;
import io.vertx.core.Vertx;
public class PostgreSQLAsyncExample {
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
PgConnectOptions options = new PgConnectOptions()
.setPort(5432)
.setHost("localhost")
.setDatabase("mydatabase")
.setUser("myuser")
.setPassword("mypassword");
PgClient client = PgClient.pool(vertx, options);
client.getConnection(conn -> {
if (conn.succeeded()) {
PgConnection connection = conn.result();
connection.query("SELECT * FROM users", res -> {
if (res.succeeded()) {
PgRowSet rowSet = res.result();
System.out.println("Query result: " + rowSet);
} else {
System.out.println("Query failed: " + res.cause());
}
connection.close();
});
} else {
System.out.println("Connection failed: " + conn.cause());
}
});
}
}
(Note: This is a simplified example for illustrative purposes. In a real-world application, you would need to handle exceptions, manage database transactions, and ensure proper resource cleanup.)