Class Statement (6.102.0)
public final class Statement implements Serializable
A SQL statement and optional bound parameters that can be executed in a 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 >
Statement
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 |
String
|
of(String sql)
public static Statement of(String sql)
Creates a Statement
with the given SQL text sql
.
Parameter |
Name |
Description |
sql |
String
|
of(String sql, ImmutableMap<String,Value> parameters)
public static Statement of(String sql, ImmutableMap<String,Value> parameters)
Creates a Statement with the given SQL text and parameters.
Parameters |
Name |
Description |
sql |
String
|
parameters |
com.google.common.collect.ImmutableMap<String,Value>
|
Methods
analyzeQuery(ReadContext context, ReadContext.QueryAnalyzeMode queryMode)
public ResultSet analyzeQuery(ReadContext context, ReadContext.QueryAnalyzeMode queryMode)
equals(Object o)
public boolean equals(Object o)
Parameter |
Name |
Description |
o |
Object
|
Overrides
executeQuery(ReadContext context, Options.QueryOption[] options)
public ResultSet executeQuery(ReadContext context, Options.QueryOption[] options)
getParameters()
public Map<String,Value> getParameters()
Returns the parameters bound to this Statement
.
getQueryOptions()
public ExecuteSqlRequest.QueryOptions getQueryOptions()
Returns the QueryOptions that will be used with this Statement.
getSql()
Returns the current SQL statement text.
Returns |
Type |
Description |
String |
|
hasBinding(String parameter)
public boolean hasBinding(String parameter)
Returns true
if a binding exists for parameter
.
Parameter |
Name |
Description |
parameter |
String
|
hashCode()
Returns |
Type |
Description |
int |
|
Overrides
toBuilder()
public Statement.Builder toBuilder()
toString()
Returns |
Type |
Description |
String |
|
Overrides
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 |
String
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-10-11 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-10-11 UTC."],[],[]]