Package oracle.nosql.driver.ops
Class PreparedStatement
- java.lang.Object
-
- oracle.nosql.driver.ops.PreparedStatement
-
public class PreparedStatement extends Object
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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearVariables()
Clears all bind variables from the statement.PreparedStatement
copyStatement()
Returns a new instance that shares this object's prepared query, which is immutable, but does not share its variables.String
getQueryPlan()
Returns a string representation of the query execution plan, if it was requested in thePrepareRequest
; null otherwise.String
getSQLText()
Returns the SQL text of this PreparedStatement.Map<String,FieldValue>
getVariables()
Returns the map of variables to use for a prepared query with variables.PreparedStatement
setVariable(String name, FieldValue value)
Sets the named variable in the map of variables to use for the query.
-
-
-
Method Detail
-
copyStatement
public PreparedStatement 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
public String getSQLText()
Returns the SQL text of this PreparedStatement.- Returns:
- the SQL text of this PreparedStatement.
-
getQueryPlan
public String 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
-
getVariables
public Map<String,FieldValue> 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
public PreparedStatement setVariable(String name, FieldValue value)
Sets the named variable in the map of variables to use for the query. Existing variables with the same name are silently overwritten. The names and types are validated when the query is executed.- Parameters:
name
- the variable name used in the query statementvalue
- the value- Returns:
- this
-
-