== Using connections

When you need to execute sequential queries (without a transaction), you can create a new connection
or borrow one from the pool:

[source,ruby]
----
Code not translatable
----

Prepared queries can be created:

[source,ruby]
----
require 'vertx-sql-client/tuple'
connection.prepare("SELECT * FROM users WHERE first_name LIKE ?") { |ar1_err,ar1|
  if (ar1_err == nil)
    pq = ar1
    pq.execute(VertxSqlClient::Tuple.of("julien")) { |ar2_err,ar2|
      if (ar2_err == nil)
        # All rows
        rows = ar2
      end
    }
  end
}

----

NOTE: prepared query caching depends on the `link:../dataobjects.html#SqlConnectOptions#set_cache_prepared_statements-instance_method[cachePreparedStatements]` and
does not depend on whether you are creating prepared queries or use `link:../../yardoc/VertxSqlClient/SqlClient.html#prepared_query-instance_method[direct prepared queries]`

`link:../../yardoc/VertxSqlClient/PreparedQuery.html[PreparedQuery]` can perform efficient batching:

[source,ruby]
----
require 'vertx-sql-client/tuple'
connection.prepare("INSERT INTO USERS (id, name) VALUES (?, ?)") { |ar1_err,ar1|
  if (ar1_err == nil)
    prepared = ar1

    # Create a query : bind parameters
    batch = Array.new

    # Add commands to the createBatch
    batch.push(VertxSqlClient::Tuple.of("julien", "Julien Viet"))
    batch.push(VertxSqlClient::Tuple.of("emad", "Emad Alblueshi"))

    prepared.batch(batch) { |res_err,res|
      if (res_err == nil)

        # Process rows
        rows = res
      else
        puts "Batch failed #{res_err}"
      end
    }
  end
}

----