use of io.vertx.db2client.DB2Pool in project vertx-sql-client by eclipse-vertx.
the class DB2ClientExamples method connecting04.
public void connecting04(Vertx vertx) {
// Connect options
DB2ConnectOptions connectOptions = new DB2ConnectOptions().setPort(50000).setHost("the-host").setDatabase("the-db").setUser("user").setPassword("secret");
// Pool options
PoolOptions poolOptions = new PoolOptions().setMaxSize(5);
// Create the pooled client
DB2Pool client = DB2Pool.pool(vertx, connectOptions, poolOptions);
// Get a connection from the pool
client.getConnection().compose(conn -> {
System.out.println("Got a connection from the pool");
// All operations execute on the same connection
return conn.query("SELECT * FROM users WHERE id='julien'").execute().compose(res -> conn.query("SELECT * FROM users WHERE id='emad'").execute()).onComplete(ar -> {
// Release the connection to the pool
conn.close();
});
}).onComplete(ar -> {
if (ar.succeeded()) {
System.out.println("Done");
} else {
System.out.println("Something went wrong " + ar.cause().getMessage());
}
});
}
use of io.vertx.db2client.DB2Pool in project vertx-sql-client by eclipse-vertx.
the class DB2ClientExamples method configureFromDataObject.
public void configureFromDataObject(Vertx vertx) {
// Data object
DB2ConnectOptions connectOptions = new DB2ConnectOptions().setPort(50000).setHost("the-host").setDatabase("the-db").setUser("user").setPassword("secret");
// Pool Options
PoolOptions poolOptions = new PoolOptions().setMaxSize(5);
// Create the pool from the data object
DB2Pool pool = DB2Pool.pool(vertx, connectOptions, poolOptions);
pool.getConnection(ar -> {
// Handling your connection
});
}
use of io.vertx.db2client.DB2Pool in project vertx-sql-client by eclipse-vertx.
the class DB2ClientExamples method configureFromUri.
public void configureFromUri(Vertx vertx) {
// Connection URI
String connectionUri = "db2://dbuser:secretpassword@database.server.com:50000/mydb";
// Create the pool from the connection URI
DB2Pool pool = DB2Pool.pool(connectionUri);
// Create the connection from the connection URI
DB2Connection.connect(vertx, connectionUri, res -> {
// Handling your connection
});
}
use of io.vertx.db2client.DB2Pool in project vertx-sql-client by eclipse-vertx.
the class DB2ClientExamples method gettingStarted.
public void gettingStarted() {
// Connect options
DB2ConnectOptions connectOptions = new DB2ConnectOptions().setPort(50000).setHost("the-host").setDatabase("the-db").setUser("user").setPassword("secret");
// Pool options
PoolOptions poolOptions = new PoolOptions().setMaxSize(5);
// Create the client pool
DB2Pool client = DB2Pool.pool(connectOptions, poolOptions);
// A simple query
client.query("SELECT * FROM users WHERE id='julien'").execute(ar -> {
if (ar.succeeded()) {
RowSet<Row> result = ar.result();
System.out.println("Got " + result.size() + " rows ");
} else {
System.out.println("Failure: " + ar.cause().getMessage());
}
// Now close the pool
client.close();
});
}
use of io.vertx.db2client.DB2Pool in project vertx-sql-client by eclipse-vertx.
the class DB2ClientExamples method poolVersusPooledClient.
public void poolVersusPooledClient(Vertx vertx, String sql, DB2ConnectOptions connectOptions, PoolOptions poolOptions) {
// Pooled client
SqlClient pooledClient = DB2Pool.client(vertx, connectOptions, poolOptions);
// Pipelined
Future<RowSet<Row>> res1 = pooledClient.query(sql).execute();
// Connection pool
DB2Pool pool = DB2Pool.pool(vertx, connectOptions, poolOptions);
// Not pipelined
Future<RowSet<Row>> res2 = pool.query(sql).execute();
}
Aggregations