Example usage for io.vertx.pgclient PgPool pool

List of usage examples for io.vertx.pgclient PgPool pool

Introduction

In this page you can find the example usage for io.vertx.pgclient PgPool pool.

Prototype

static PgPool pool(PgConnectOptions connectOptions, PoolOptions poolOptions) 

Source Link

Document

Create a connection pool to the database configured with the given connectOptions and poolOptions .

Usage

From source file:examples.PgClientExamples.java

License:Apache License

public void gettingStarted() {

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

    // Pool options
    PoolOptions poolOptions = new PoolOptions().setMaxSize(5);

    // Create the client pool
    PgPool client = PgPool.pool(connectOptions, poolOptions);

    // A simple query
    client.query("SELECT * FROM users WHERE id='julien'", ar -> {
        if (ar.succeeded()) {
            RowSet<Row> result = ar.result();
            System.out.println("Got " + result.size() + " rows ");
        } else {/*from   w  w w.  ja  va 2s  .  c  om*/
            System.out.println("Failure: " + ar.cause().getMessage());
        }

        // Now close the pool
        client.close();
    });
}

From source file:examples.PgClientExamples.java

License:Apache License

public void connecting01() {

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

    // Pool options
    PoolOptions poolOptions = new PoolOptions().setMaxSize(5);

    // Create the pooled client
    PgPool client = PgPool.pool(connectOptions, poolOptions);
}

From source file:examples.PgClientExamples.java

License:Apache License

public void connecting06(Vertx vertx) {

    // Connect Options
    // Socket file name will be /var/run/postgresql/.s.PGSQL.5432
    PgConnectOptions connectOptions = new PgConnectOptions().setHost("/var/run/postgresql").setPort(5432)
            .setDatabase("the-db");

    // Pool options
    PoolOptions poolOptions = new PoolOptions().setMaxSize(5);

    // Create the pooled client
    PgPool client = PgPool.pool(connectOptions, poolOptions);

    // Create the pooled client with a vertx instance
    // Make sure the vertx instance has enabled native transports
    PgPool client2 = PgPool.pool(vertx, connectOptions, poolOptions);
}