List of usage examples for io.vertx.sqlclient SqlClient query
@Fluent SqlClient query(String sql, Handler<AsyncResult<RowSet<Row>>> handler);
From source file:examples.MySQLClientExamples.java
public void lastInsertId(SqlClient client) { client.query("INSERT INTO test(val) VALUES ('v1')", ar -> { if (ar.succeeded()) { RowSet<Row> rows = ar.result(); long lastInsertId = rows.property(MySQLClient.LAST_INSERTED_ID); System.out.println("Last inserted id is: " + lastInsertId); } else {/* w w w.jav a2 s. c o m*/ System.out.println("Failure: " + ar.cause().getMessage()); } }); }
From source file:examples.MySQLClientExamples.java
public void booleanExample01(SqlClient client) { client.query("SELECT graduated FROM students WHERE id = 0", ar -> { if (ar.succeeded()) { RowSet<Row> rowSet = ar.result(); for (Row row : rowSet) { int pos = row.getColumnIndex("graduated"); Byte value = row.get(Byte.class, pos); Boolean graduated = row.getBoolean("graduated"); }/* w w w. ja v a 2 s.co m*/ } else { System.out.println("Failure: " + ar.cause().getMessage()); } }); }
From source file:examples.MySQLClientExamples.java
public void storedProcedureExample(SqlClient client) { client.query("CREATE PROCEDURE multi() BEGIN\n" + " SELECT 1;\n" + " SELECT 1;\n" + " INSERT INTO ins VALUES (1);\n" + " INSERT INTO ins VALUES (2);\n" + "END;", ar1 -> { if (ar1.succeeded()) { // create stored procedure success client.query("CALL multi();", ar2 -> { if (ar2.succeeded()) { // handle the result RowSet<Row> result1 = ar2.result(); Row row1 = result1.iterator().next(); System.out.println("First result: " + row1.getInteger(0)); RowSet<Row> result2 = result1.next(); Row row2 = result2.iterator().next(); System.out.println("Second result: " + row2.getInteger(0)); RowSet<Row> result3 = result2.next(); System.out.println("Affected rows: " + result3.rowCount()); } else { System.out.println("Failure: " + ar2.cause().getMessage()); }/* w ww . jav a 2s. c o m*/ }); } else { System.out.println("Failure: " + ar1.cause().getMessage()); } }); }
From source file:examples.SqlClientExamples.java
License:Apache License
public void queries01(SqlClient client) { 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 ww w . j av a2 s . com System.out.println("Failure: " + ar.cause().getMessage()); } }); }