Example usage for io.vertx.pgclient PgConnection connect

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

Introduction

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

Prototype

static void connect(Vertx vertx, String connectionUri, Handler<AsyncResult<PgConnection>> handler) 

Source Link

Document

Like #connect(Vertx,PgConnectOptions,Handler) with options build from connectionUri .

Usage

From source file:examples.PgClientExamples.java

License:Apache License

public void configureFromUri(Vertx vertx) {

    // Connection URI
    String connectionUri = "postgresql://dbuser:secretpassword@database.server.com:3211/mydb";

    // Create the pool from the connection URI
    PgPool pool = PgPool.pool(connectionUri);

    // Create the connection from the connection URI
    PgConnection.connect(vertx, connectionUri, res -> {
        // Handling your connection
    });/*from  www . j  av  a2 s  .  co  m*/
}

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 ww w . j  a  v  a  2 s  .  c  om*/
                    });
                } else {
                    // Close the connection
                    conn.close();
                }
            });
        } else {
            System.out.println("Could not connect: " + res.cause().getMessage());
        }
    });
}

From source file:examples.PgClientExamples.java

License:Apache License

public void ex10(Vertx vertx) {

    PgConnectOptions options = new PgConnectOptions().setPort(5432).setHost("the-host").setDatabase("the-db")
            .setUser("user").setPassword("secret").setSslMode(SslMode.VERIFY_CA)
            .setPemTrustOptions(new PemTrustOptions().addCertPath("/path/to/cert.pem"));

    PgConnection.connect(vertx, options, res -> {
        if (res.succeeded()) {
            // Connected with SSL
        } else {//from ww w . j  a  va 2s  .  c  o  m
            System.out.println("Could not connect " + res.cause());
        }
    });
}