Example usage for io.vertx.sqlclient SqlClient preparedQuery

List of usage examples for io.vertx.sqlclient SqlClient preparedQuery

Introduction

In this page you can find the example usage for io.vertx.sqlclient SqlClient preparedQuery.

Prototype

@Fluent
SqlClient preparedQuery(String sql, Tuple arguments, Handler<AsyncResult<RowSet<Row>>> handler);

Source Link

Document

Prepare and execute a query.

Usage

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   w ww .  j a  va 2s . c om*/
            System.out.println("Failure: " + ar.cause().getMessage());
        }
    });
}

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. j  a  va 2s. c  o  m*/
        } else {
            System.out.println("Failure: " + ar.cause().getMessage());
        }
    });
}

From source file:examples.PgClientExamples.java

License:Apache License

public void customType02Example(SqlClient client) {
    client.preparedQuery("INSERT INTO address_book (id, address) VALUES ($1, $2)",
            Tuple.of(3, "('Anytown', 'Second Ave', false)"), ar -> {
                if (ar.succeeded()) {
                    RowSet<Row> rows = ar.result();
                    System.out.println(rows.rowCount());
                } else {
                    System.out.println("Failure: " + ar.cause().getMessage());
                }/*from   w  w  w. ja  va 2s  .  c o  m*/
            });
}

From source file:examples.PgClientExamples.java

License:Apache License

public void tsQuery01Example(SqlClient client) {
    client.preparedQuery("SELECT to_tsvector( $1 ) @@ to_tsquery( $2 )",
            Tuple.of("fat cats ate fat rats", "fat & rat"), ar -> {
                if (ar.succeeded()) {
                    RowSet<Row> rows = ar.result();
                    for (Row row : rows) {
                        System.out.println("Match : " + row.getBoolean(0));
                    }// ww  w . j a v a 2  s.  co  m
                } else {
                    System.out.println("Failure: " + ar.cause().getMessage());
                }
            });
}

From source file:examples.PgClientExamples.java

License:Apache License

public void tsQuery02Example(SqlClient client) {
    client.preparedQuery("SELECT to_tsvector( $1 ), to_tsquery( $2 )",
            Tuple.of("fat cats ate fat rats", "fat & rat"), ar -> {
                if (ar.succeeded()) {
                    RowSet<Row> rows = ar.result();
                    for (Row row : rows) {
                        System.out.println("Vector : " + row.getString(0) + ", query : " + row.getString(1));
                    }/*w w  w  . j av  a  2s  .c  om*/
                } else {
                    System.out.println("Failure: " + ar.cause().getMessage());
                }
            });
}

From source file:examples.PgClientExamples.java

License:Apache License

public void returning(SqlClient client) {
    client.preparedQuery("INSERT INTO color (color_name) VALUES ($1), ($2), ($3) RETURNING color_id",
            Tuple.of("white", "red", "blue"), ar -> {
                if (ar.succeeded()) {
                    RowSet<Row> rows = ar.result();
                    System.out.println(rows.rowCount());
                    for (Row row : rows) {
                        System.out.println("generated key: " + row.getInteger("color_id"));
                    }/*from   w w w.ja  v  a  2 s  .c om*/
                } 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 {// w w  w .j  a  va2 s  .c  o  m
            System.out.println("Failure: " + ar.cause().getMessage());
        }
    });
}

From source file:examples.SqlClientExamples.java

License:Apache License

public void queries04(SqlClient client) {
    client.preparedQuery("INSERT INTO users (first_name, last_name) VALUES ($1, $2)",
            Tuple.of("Julien", "Viet"), ar -> {
                if (ar.succeeded()) {
                    RowSet<Row> rows = ar.result();
                    System.out.println(rows.rowCount());
                } else {
                    System.out.println("Failure: " + ar.cause().getMessage());
                }//from  w w w.  ja  va 2s.co  m
            });
}

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 {// w w w  .j av  a  2 s  .c  om
            System.out.println("Failure: " + ar.cause().getMessage());
        }
    });
}

From source file:examples.SqlClientExamples.java

License:Apache License

public void queries04(SqlClient client) {
    client.preparedQuery("INSERT INTO users (first_name, last_name) VALUES (?, ?)", Tuple.of("Julien", "Viet"),
            ar -> {/*from www. jav  a 2 s.  c om*/
                if (ar.succeeded()) {
                    RowSet<Row> rows = ar.result();
                    System.out.println(rows.rowCount());
                } else {
                    System.out.println("Failure: " + ar.cause().getMessage());
                }
            });
}