List of usage examples for io.vertx.sqlclient Tuple of
static Tuple of(Object elt1)
From source file:examples.MySQLClientExamples.java
public void booleanExample02(SqlClient client) { client.preparedQuery("UPDATE students SET graduated = ? WHERE id = 0", Tuple.of(true), ar -> { if (ar.succeeded()) { System.out.println("Updated with the boolean value"); } else {/*from ww w . j a v a2 s .co m*/ System.out.println("Failure: " + ar.cause().getMessage()); } }); }
From source file:examples.PgClientExamples.java
License:Apache License
public void arrayExample() { // Create a tuple with a single array Tuple tuple = Tuple.of(new String[] { "a", "tuple", "with", "arrays" }); // Add a string array to the tuple tuple.addStringArray(new String[] { "another", "array" }); // Get the first array of string String[] array = tuple.getStringArray(0); }
From source file:examples.PgClientExamples.java
License:Apache License
public void customType01Example(SqlClient client) { client.preparedQuery("SELECT address, (address).city FROM address_book WHERE id=$1", Tuple.of(3), ar -> { if (ar.succeeded()) { RowSet<Row> rows = ar.result(); for (Row row : rows) { System.out.println("Full Address " + row.getString(0) + ", City " + row.getString(1)); }//w w w.ja va2 s.c o m } else { System.out.println("Failure: " + ar.cause().getMessage()); } }); }
From source file:examples.SqlClientExamples.java
License:Apache License
public void queries02(SqlClient client) { client.preparedQuery("SELECT * FROM users WHERE id=$1", Tuple.of("julien"), ar -> { if (ar.succeeded()) { RowSet<Row> rows = ar.result(); System.out.println("Got " + rows.size() + " rows "); } else {//from w w w .j a v a 2 s . co m System.out.println("Failure: " + ar.cause().getMessage()); } }); }
From source file:examples.SqlClientExamples.java
License:Apache License
public void usingConnections02(SqlConnection connection) { connection.prepare("SELECT * FROM users WHERE first_name LIKE $1", ar1 -> { if (ar1.succeeded()) { PreparedQuery pq = ar1.result(); pq.execute(Tuple.of("julien"), ar2 -> { if (ar2.succeeded()) { // All rows RowSet<Row> rows = ar2.result(); }//from w ww.j a v a 2 s.c o m }); } }); }
From source file:examples.SqlClientExamples.java
License:Apache License
public void usingCursors01(SqlConnection connection) { connection.prepare("SELECT * FROM users WHERE first_name LIKE $1", ar1 -> { if (ar1.succeeded()) { PreparedQuery pq = ar1.result(); // Cursors require to run within a transaction Transaction tx = connection.begin(); // Create a cursor Cursor cursor = pq.cursor(Tuple.of("julien")); // Read 50 rows cursor.read(50, ar2 -> {// w w w . j a v a 2s.com if (ar2.succeeded()) { RowSet<Row> rows = ar2.result(); // Check for more ? if (cursor.hasMore()) { // Repeat the process... } else { // No more rows - commit the transaction tx.commit(); } } }); } }); }
From source file:examples.SqlClientExamples.java
License:Apache License
public void usingCursors03(SqlConnection connection) { connection.prepare("SELECT * FROM users WHERE first_name LIKE $1", ar1 -> { if (ar1.succeeded()) { PreparedQuery pq = ar1.result(); // Streams require to run within a transaction Transaction tx = connection.begin(); // Fetch 50 rows at a time RowStream<Row> stream = pq.createStream(50, Tuple.of("julien")); // Use the stream stream.exceptionHandler(err -> { System.out.println("Error: " + err.getMessage()); });//from w ww . j a va2 s . com stream.endHandler(v -> { tx.commit(); System.out.println("End of stream"); }); stream.handler(row -> { System.out.println("User: " + row.getString("last_name")); }); } }); }
From source file:examples.SqlClientExamples.java
License:Apache License
public void queries02(SqlClient client) { client.preparedQuery("SELECT * FROM users WHERE id=?", Tuple.of("julien"), ar -> { if (ar.succeeded()) { RowSet<Row> rows = ar.result(); System.out.println("Got " + rows.size() + " rows "); } else {/*from ww w. j av a 2 s . com*/ System.out.println("Failure: " + ar.cause().getMessage()); } }); }
From source file:examples.SqlClientExamples.java
License:Apache License
public void usingConnections02(SqlConnection connection) { connection.prepare("SELECT * FROM users WHERE first_name LIKE ?", ar1 -> { if (ar1.succeeded()) { PreparedQuery pq = ar1.result(); pq.execute(Tuple.of("julien"), ar2 -> { if (ar2.succeeded()) { // All rows RowSet<Row> rows = ar2.result(); }/* ww w . j ava 2 s.c om*/ }); } }); }
From source file:examples.SqlClientExamples.java
License:Apache License
public void usingCursors01(SqlConnection connection) { connection.prepare("SELECT * FROM users WHERE age > ?", ar1 -> { if (ar1.succeeded()) { PreparedQuery pq = ar1.result(); // Create a cursor Cursor cursor = pq.cursor(Tuple.of(18)); // Read 50 rows cursor.read(50, ar2 -> {/*from w w w .ja v a2 s. c om*/ if (ar2.succeeded()) { RowSet<Row> rows = ar2.result(); // Check for more ? if (cursor.hasMore()) { // Repeat the process... } else { // No more rows - close the cursor cursor.close(); } } }); } }); }