All Downloads are FREE. Search and download functionalities are using the official Maven repository.

x-sql-client.4.5.4.source-code.queries.adoc Maven / Gradle / Ivy

There is a newer version: 5.0.0.CR1
Show newest version
= Running queries

When you don't need a transaction or run single queries, you can run queries directly on the pool; the pool
will use one of its connection to run the query and return the result to you.

Here is how to run simple queries:

[source,$lang]
----
{@link examples.SqlClientExamples#queries01(io.vertx.sqlclient.SqlClient)}
----

== Prepared queries

You can do the same with prepared queries.

The SQL string can refer to parameters by position, using the database syntax {PREPARED_PARAMS}

[source,$lang]
----
{@link examples.SqlClientExamples#queries02(io.vertx.sqlclient.SqlClient)}
----

Query methods provides an asynchronous {@link io.vertx.sqlclient.RowSet} instance that works for _SELECT_ queries

[source,$lang]
----
{@link examples.SqlClientExamples#queries03(io.vertx.sqlclient.SqlClient)}
----

or _UPDATE_/_INSERT_ queries:

[source,$lang]
----
{@link examples.SqlClientExamples#queries04(io.vertx.sqlclient.SqlClient)}
----

The {@link io.vertx.sqlclient.Row} gives you access to your data by index

[source,$lang]
----
{@link examples.SqlClientExamples#queries05(io.vertx.sqlclient.Row)}
----

CAUTION: Column indexes start at 0, not at 1.

Alternatively, data can be retrieved by name:

[source,$lang]
----
{@link examples.SqlClientExamples#queries06(io.vertx.sqlclient.Row)}
----

The client will not do any magic here and the column name is identified with the name in the table regardless of how your SQL text is.

You can access a wide variety of of types

[source,$lang]
----
{@link examples.SqlClientExamples#queries07(io.vertx.sqlclient.Row)}
----

You can use cached prepared statements to execute one-shot prepared queries:

[source,$lang]
----
{@link examples.SqlClientExamples#queries09(io.vertx.sqlclient.SqlClient, SqlConnectOptions)}
----

You can create a `PreparedStatement` and manage the lifecycle by yourself.

[source,$lang]
----
{@link examples.SqlClientExamples#queries10(io.vertx.sqlclient.SqlConnection)}
----

ifndef::batching-unsupported[]
== Batches

You can execute prepared batch

[source,$lang]
----
{@link examples.SqlClientExamples#queries08(io.vertx.sqlclient.SqlClient)}
----
endif::[]




© 2015 - 2024 Weber Informatics LLC | Privacy Policy