Package oracle.nosql.driver.ops
Class PreparedStatement
java.lang.Object
oracle.nosql.driver.ops.PreparedStatement
A class encapsulating a prepared query statement. It includes state that
can be sent to a server and executed without re-parsing the query. It
includes bind variables which may be set for each successive use of the
query. The prepared query itself is read-only but this object contains a
mutable map of bind variables and is not thread-safe if variables are
used.
A single instance of PreparedStatement is thread-safe if bind variables
are not used. If bind variables are to be used and the statement
shared among threads additional instances of PreparedStatement can be
constructed using copyStatement()
.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears all bind variables from the statement.Returns a new instance that shares this object's prepared query, which is immutable, but does not share its variables.Returns a string representation of the query execution plan, if it was requested in thePrepareRequest
; null otherwise.Returns a string (JSON) representation of the schema of the query result for this query, if it was requested in thePrepareRequest
; null otherwise.Returns the SQL text of this PreparedStatement.Returns the map of variables to use for a prepared query with variables.setVariable
(int pos, FieldValue value) Binds an external variable to a given value.setVariable
(String name, FieldValue value) Binds an external variable to a given value.
-
Method Details
-
copyStatement
Returns a new instance that shares this object's prepared query, which is immutable, but does not share its variables.- Returns:
- a new PreparedStatement using this instance's prepared query. Bind variables are uninitialized.
-
getSQLText
Returns the SQL text of this PreparedStatement.- Returns:
- the SQL text of this PreparedStatement.
-
getQueryPlan
Returns a string representation of the query execution plan, if it was requested in thePrepareRequest
; null otherwise.- Returns:
- the string representation of the query execution plan
-
getQuerySchema
Returns a string (JSON) representation of the schema of the query result for this query, if it was requested in thePrepareRequest
; null otherwise.- Returns:
- the string representation of the query schema
- Since:
- 5.4
-
getVariables
Returns the map of variables to use for a prepared query with variables.- Returns:
- the map, or null if there are no variables set.
-
clearVariables
public void clearVariables()Clears all bind variables from the statement. -
setVariable
Binds an external variable to a given value. The variable is identified by its name.- Parameters:
name
- the name of the variablevalue
- the value- Returns:
- this
-
setVariable
Binds an external variable to a given value. The variable is identified by its position within the query string. The variable that appears first in the query text has position 1, the variable that appears second has position 2 and so on.- Parameters:
pos
- the position of the variablevalue
- the value- Returns:
- this
-