# Class Statement (6.118.0)

6.118.0 (latest) 6.116.0 6.111.1 6.108.0 6.107.0 6.103.0 6.102.1 6.101.1 6.100.0 6.99.0 6.98.1 6.97.1 6.96.1 6.95.1 6.94.0 6.93.0 6.89.0 6.88.0 6.87.0 6.86.0 6.85.0 6.83.0 6.82.0 6.80.1 6.79.0 6.77.0 6.74.1 6.72.0 6.71.0 6.69.0 6.68.0 6.66.0 6.65.1 6.62.0 6.60.0 6.58.0 6.57.0 6.56.0 6.55.0 6.54.0 6.53.0 6.52.1 6.51.0 6.50.1 6.49.0 6.25.1 6.24.0 6.23.4 6.22.0 6.21.2 6.20.0 6.19.1 6.18.0 6.17.4 6.14.1

    public final class Statement implements Serializable

A SQL statement and optional bound parameters that can be executed in a [ReadContext](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ReadContext).

The SQL query string can contain parameter placeholders. A parameter placeholder consists of
@ followed by the parameter name. Parameter names consist of any combination of
letters, numbers, and underscores.

Parameters can appear anywhere that a literal value is expected. The same parameter name can
be used more than once, for example: `WHERE id > @msg_id AND id < @msg_id + 100`

It is an error to execute an SQL query with placeholders for unbound parameters.

Statements are constructed using a builder. Parameter values are specified by calling Builder#bind(String). For example, code to build a query using the clause above and bind a value
to `id` might look like the following:


     Statement statement = Statement
         .newBuilder("SELECT name WHERE id > @msg_id AND id < @msg_id="" +="" 100")="" .bind("msg_id").to(500)="" .build();="">

`Statement` instances are immutable.

## Inheritance

[Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> Statement

## Implements

[Serializable](https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html)

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Methods

### newBuilder(String sql)

    public static Statement.Builder newBuilder(String sql)

Creates a new statement builder with the SQL text `sql`.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `sql` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement.Builder` |   |

### of(String sql)

    public static Statement of(String sql)

Creates a `Statement` with the given SQL text `sql`.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `sql` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement` |   |

### of(String sql, ImmutableMap\<String,Value\> parameters)

    public static Statement of(String sql, ImmutableMap<String,Value> parameters)

Creates a [Statement](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement) with the given SQL text and parameters.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `sql` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `parameters` | `com.google.common.collect.ImmutableMap<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html,https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Value>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement` |   |

## Methods

### analyzeQuery(ReadContext context, ReadContext.QueryAnalyzeMode queryMode)

    public ResultSet analyzeQuery(ReadContext context, ReadContext.QueryAnalyzeMode queryMode)

Analyzes the query in `context`. `statement.analyzeQuery(context, queryMode)` is
exactly equivalent to `context.analyzeQuery(statement, queryMode)`.
See Also: [ReadContext#analyzeQuery(Statement, com.google.cloud.spanner.ReadContext.QueryAnalyzeMode)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ReadContext#com_google_cloud_spanner_ReadContext_analyzeQuery_)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `context` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ReadContext` |
| `queryMode` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ReadContext.QueryAnalyzeMode` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet` |   |

### equals(Object o)

    public boolean equals(Object o)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `o` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-)

### executeQuery(ReadContext context, Options.QueryOption\[\] options)

    public ResultSet executeQuery(ReadContext context, Options.QueryOption[] options)

Executes the query in `context`. `statement.executeQuery(context)` is exactly
equivalent to `context.executeQuery(statement)`.
See Also: [ReadContext#executeQuery(Statement, Options.QueryOption...)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ReadContext#com_google_cloud_spanner_ReadContext_executeQuery_)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `context` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ReadContext` |
| `options` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Options.QueryOption[]` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet` |   |

### getParameters()

    public Map<String,Value> getParameters()

Returns the parameters bound to this `Statement`.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/Map.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html,https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Value>` |   |

### getQueryOptions()

    public ExecuteSqlRequest.QueryOptions getQueryOptions()

Returns the QueryOptions that will be used with this [Statement](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement).

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.spanner.v1.ExecuteSqlRequest.QueryOptions` |   |

### getSql()

    public String getSql()

Returns the current SQL statement text.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### hasBinding(String parameter)

    public boolean hasBinding(String parameter)

Returns `true` if a binding exists for `parameter`.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `parameter` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### hashCode()

    public int hashCode()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--)

### toBuilder()

    public Statement.Builder toBuilder()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement.Builder` |   |

### toString()

    public String toString()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

**Overrides** [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--)

### withReplacedSql(String sql)

    public Statement withReplacedSql(String sql)

Returns a copy of this statement with the SQL string replaced by the given SQL string.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `sql` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement` |   |