Example usage for io.vertx.pgclient PgConnection close

List of usage examples for io.vertx.pgclient PgConnection close

Introduction

In this page you can find the example usage for io.vertx.pgclient PgConnection close.

Prototype

void close();

Source Link

Document

Close the current connection after all the pending commands have been processed.

Usage

From source file:examples.PgClientExamples.java

License:Apache License

public void connecting05(Vertx vertx) {

    // Pool options
    PgConnectOptions options = new PgConnectOptions().setPort(5432).setHost("the-host").setDatabase("the-db")
            .setUser("user").setPassword("secret");

    // Connect to Postgres
    PgConnection.connect(vertx, options, res -> {
        if (res.succeeded()) {

            System.out.println("Connected");

            // Obtain our connection
            PgConnection conn = res.result();

            // All operations execute on the same connection
            conn.query("SELECT * FROM users WHERE id='julien'", ar2 -> {
                if (ar2.succeeded()) {
                    conn.query("SELECT * FROM users WHERE id='emad'", ar3 -> {
                        // Close the connection
                        conn.close();
                    });/*from w  w w . j  a v a 2  s.com*/
                } else {
                    // Close the connection
                    conn.close();
                }
            });
        } else {
            System.out.println("Could not connect: " + res.cause().getMessage());
        }
    });
}