<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
import org.postgresql.async.AsyncConnection;
import org.postgresql.async.ConnectionPool;
ConnectionPool<AsyncConnection> connectionPool = new ConnectionPool<>(AsyncConnection.class, "jdbc:postgresql://localhost:5432/mydatabase", "username", "password");
connectionPool.getConnection(connection -> {
if (connection.succeeded()) {
AsyncConnection asyncConnection = connection.result();
asyncConnection.query("SELECT * FROM users", result -> {
if (result.succeeded()) {
ResultSet resultSet = result.result();
// ...
} else {
Throwable error = result.cause();
// ...
}
});
} else {
Throwable error = connection.cause();
// ...
}
});
import org.postgresql.async.AsyncConnection;
import org.postgresql.async.QueryResultHandler;
AsyncConnection asyncConnection = ...
List<User> users = ...
String query = "INSERT INTO users (name, email) VALUES ($1, $2)";
QueryResultHandler<Void> handler = result -> {
if (result.succeeded()) {
} else {
}
};
for (User user : users) {
asyncConnection.queryParams(query, user.getName(), user.getEmail(), handler);
}