| 1 | ## Statements |
| 2 | |
| 3 | To execute a query, you create a [Statement] instance and pass it to |
| 4 | `Session#execute()`. The driver provides various implementations: |
| 5 | |
| 6 | * [SimpleStatement]: a simple implementation built directly from a |
| 7 | character string. Typically used for queries that are executed only |
| 8 | once or a few times. |
| 9 | * [BoundStatement]: obtained by binding values to a [prepared |
| 10 | statement](prepared/). Typically used for queries that are executed |
| 11 | often, with different values. |
| 12 | * [BuiltStatement]: a statement built with the [QueryBuilder] DSL. It |
| 13 | can be executed directly like a simple statement, or prepared. |
| 14 | * [BatchStatement]: a statement that groups multiple statements to be |
| 15 | executed as a batch. |
| 16 | |
| 17 | `Session` also has a shortcut to build and execute a simple statement in |
| 18 | a single call: |
| 19 | |
| 20 | ```java |
| 21 | session.execute("select release_version from system.local"); |
| 22 | |
| 23 | // Is equivalent to: |
| 24 | Statement s = new SimpleStatement("select release_version from system.local"); |
| 25 | session.execute(s); |
| 26 | ``` |
| 27 | |
| 28 | ### Customizing execution |
| 29 | |
| 30 | Before executing a statement, you might want to customize certain |
| 31 | aspects of its execution. `Statement` provides a number of methods for |
| 32 | this, for example: |
| 33 | |
| 34 | ```java |
| 35 | Statement s = new SimpleStatement("select release_version from system.local"); |
| 36 | s.enableTracing(); |
| 37 | session.execute(s); |
| 38 | ``` |
| 39 | |
| 40 | If you use custom policies ([RetryPolicy], [LoadBalancingPolicy], |
| 41 | [SpeculativeExecutionPolicy]...), you might also want to have custom |
| 42 | properties that influence statement execution. To achieve this, you can |
| 43 | wrap your statements in a custom [StatementWrapper] implementation. |
| 44 | |
| 45 | [Statement]: http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/Statement.html |
| 46 | [SimpleStatement]: http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/SimpleStatement.html |
| 47 | [BoundStatement]: http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/BoundStatement.html |
| 48 | [BatchStatement]: http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/BatchStatement.html |
| 49 | [QueryBuilder]: http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/querybuilder/QueryBuilder.html |
| 50 | [BuiltStatement]: http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/querybuilder/BuiltStatement.html |
| 51 | [StatementWrapper]: http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/StatementWrapper.html |
| 52 | [RetryPolicy]: http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/policies/RetryPolicy.html |
| 53 | [LoadBalancingPolicy]: http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/policies/LoadBalancingPolicy.html |
| 54 | [SpeculativeExecutionPolicy]: http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/policies/SpeculativeExecutionPolicy.html |