List of usage examples for io.vertx.mysqlclient MySQLConnectOptions MySQLConnectOptions
public MySQLConnectOptions()
From source file:examples.MySQLClientExamples.java
public void gettingStarted() { // Connect options MySQLConnectOptions connectOptions = new MySQLConnectOptions().setPort(3306).setHost("the-host") .setDatabase("the-db").setUser("user").setPassword("secret"); // Pool options PoolOptions poolOptions = new PoolOptions().setMaxSize(5); // Create the client pool MySQLPool client = MySQLPool.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 {/* w w w .j av a2 s .c o m*/ System.out.println("Failure: " + ar.cause().getMessage()); } // Now close the pool client.close(); }); }
From source file:examples.MySQLClientExamples.java
public void configureFromDataObject(Vertx vertx) { // Data object MySQLConnectOptions connectOptions = new MySQLConnectOptions().setPort(3306).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 MySQLPool pool = MySQLPool.pool(vertx, connectOptions, poolOptions); pool.getConnection(ar -> {/*from ww w . ja v a 2 s . c om*/ // Handling your connection }); }
From source file:examples.MySQLClientExamples.java
public void configureConnectionCharset() { MySQLConnectOptions connectOptions = new MySQLConnectOptions(); // set connection character set to utf8 instead of the default charset utf8mb4 connectOptions.setCharset("utf8"); }
From source file:examples.MySQLClientExamples.java
public void configureConnectionCollation() { MySQLConnectOptions connectOptions = new MySQLConnectOptions(); // set connection collation to utf8_general_ci instead of the default collation utf8mb4_general_ci // setting a collation will override the charset option connectOptions.setCharset("gbk"); connectOptions.setCollation("utf8_general_ci"); }
From source file:examples.MySQLClientExamples.java
public void configureConnectionAttributes() { // Data object MySQLConnectOptions connectOptions = new MySQLConnectOptions(); // Add a connection attribute connectOptions.addProperty("_java_version", "1.8.0_212"); // Override the attributes Map<String, String> attributes = new HashMap<>(); attributes.put("_client_name", "myapp"); attributes.put("_client_version", "1.0.0"); connectOptions.setProperties(attributes); }
From source file:examples.MySQLClientExamples.java
public void connecting01() { // Connect options MySQLConnectOptions connectOptions = new MySQLConnectOptions().setPort(3306).setHost("the-host") .setDatabase("the-db").setUser("user").setPassword("secret"); // Pool options PoolOptions poolOptions = new PoolOptions().setMaxSize(5); // Create the pooled client MySQLPool client = MySQLPool.pool(connectOptions, poolOptions); }
From source file:examples.MySQLClientExamples.java
public void connecting02(Vertx vertx) { // Connect options MySQLConnectOptions connectOptions = new MySQLConnectOptions().setPort(3306).setHost("the-host") .setDatabase("the-db").setUser("user").setPassword("secret"); // Pool options PoolOptions poolOptions = new PoolOptions().setMaxSize(5); // Create the pooled client MySQLPool client = MySQLPool.pool(vertx, connectOptions, poolOptions); }
From source file:examples.MySQLClientExamples.java
public void connecting04(Vertx vertx) { // Connect options MySQLConnectOptions connectOptions = new MySQLConnectOptions().setPort(3306).setHost("the-host") .setDatabase("the-db").setUser("user").setPassword("secret"); // Pool options PoolOptions poolOptions = new PoolOptions().setMaxSize(5); // Create the pooled client MySQLPool client = MySQLPool.pool(vertx, connectOptions, poolOptions); // Get a connection from the pool client.getConnection(ar1 -> {/*from ww w. ja v a 2 s . c om*/ if (ar1.succeeded()) { System.out.println("Connected"); // Obtain our connection SqlConnection conn = ar1.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 -> { // Release the connection to the pool conn.close(); }); } else { // Release the connection to the pool conn.close(); } }); } else { System.out.println("Could not connect: " + ar1.cause().getMessage()); } }); }
From source file:examples.MySQLClientExamples.java
public void rsaPublicKeyExample() { MySQLConnectOptions options1 = new MySQLConnectOptions().setPort(3306).setHost("the-host") .setDatabase("the-db").setUser("user").setPassword("secret") .setServerRsaPublicKeyPath("tls/files/public_key.pem"); // configure with path of the public key MySQLConnectOptions options2 = new MySQLConnectOptions().setPort(3306).setHost("the-host") .setDatabase("the-db").setUser("user").setPassword("secret") .setServerRsaPublicKeyValue(Buffer.buffer("-----BEGIN PUBLIC KEY-----\n" + "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3yvG5s0qrV7jxVlp0sMj\n" + "xP0a6BuLKCMjb0o88hDsJ3xz7PpHNKazuEAfPxiRFVAV3edqfSiXoQw+lJf4haEG\n" + "HQe12Nfhs+UhcAeTKXRlZP/JNmI+BGoBduQ1rCId9bKYbXn4pvyS/a1ft7SwFkhx\n" + "aogCur7iIB0WUWvwkQ0fEj/Mlhw93lLVyx7hcGFq4FOAKFYr3A0xrHP1IdgnD8QZ\n" + "0fUbgGLWWLOossKrbUP5HWko1ghLPIbfmU6o890oj1ZWQewj1Rs9Er92/UDj/JXx\n" + "7ha1P+ZOgPBlV037KDQMS6cUh9vTablEHsMLhDZanymXzzjBkL+wH/b9cdL16LkQ\n" + "5QIDAQAB\n" + "-----END PUBLIC KEY-----\n")); // configure with buffer of the public key }
From source file:examples.MySQLClientExamples.java
public void tlsExample(Vertx vertx) { MySQLConnectOptions options = new MySQLConnectOptions().setPort(3306).setHost("the-host") .setDatabase("the-db").setUser("user").setPassword("secret").setSslMode(SslMode.VERIFY_CA) .setPemTrustOptions(new PemTrustOptions().addCertPath("/path/to/cert.pem")); MySQLConnection.connect(vertx, options, res -> { if (res.succeeded()) { // Connected with SSL } else {/*from w w w .j av a 2s . c o m*/ System.out.println("Could not connect " + res.cause()); } }); }