Class CachedPreparedStatement

java.lang.Object
org.jivesoftware.database.CachedPreparedStatement

public class CachedPreparedStatement extends Object
Allows PreparedStatement information to be cached. A prepared statement consists of a SQL statement containing bind variables as well as variable values. For example, the SQL statement "SELECT * FROM person WHERE age > ?" would have the integer variable 18 (which replaces the "?" character) to find all adults. This class encapsulates both the SQL string and bind variable values so that actual PreparedStatement can be created from that information later.
Author:
Matt Tucker
  • Constructor Details

    • CachedPreparedStatement

      public CachedPreparedStatement()
      Constructs a new CachedPreparedStatement.
    • CachedPreparedStatement

      public CachedPreparedStatement(String sql)
      Constructs a new CachedPreparedStatement.
      Parameters:
      sql - the SQL.
  • Method Details

    • getSQL

      public String getSQL()
      Returns the SQL.
      Returns:
      the SQL.
    • setSQL

      public void setSQL(String sql)
      Sets the SQL.
      Parameters:
      sql - the SQL.
    • addBoolean

      public void addBoolean(boolean value)
      Adds a boolean parameter to the prepared statement.
      Parameters:
      value - the boolean value.
    • addInt

      public void addInt(int value)
      Adds an integer parameter to the prepared statement.
      Parameters:
      value - the int value.
    • addLong

      public void addLong(long value)
      Adds a long parameter to the prepared statement.
      Parameters:
      value - the long value.
    • addString

      public void addString(String value)
      Adds a String parameter to the prepared statement.
      Parameters:
      value - the String value.
    • setParams

      public void setParams(PreparedStatement pstmt) throws SQLException
      Sets all parameters on the given PreparedStatement. The standard code block for turning a CachedPreparedStatement into a PreparedStatement is as follows:
       PreparedStatement pstmt = con.prepareStatement(cachedPstmt.getSQL());
       cachedPstmt.setParams(pstmt);
       
      Parameters:
      pstmt - the prepared statement.
      Throws:
      SQLException - if an SQL Exception occurs.
    • equals

      public boolean equals(Object object)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object