Class 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 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 the PrepareRequest; 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 statement
        value - the value
        Returns:
        this