Package org.jivesoftware.database
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 variable18
(which replaces the "?" chracter) 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 Summary
Constructors Constructor Description CachedPreparedStatement()
Constructs a new CachedPreparedStatement.CachedPreparedStatement(String sql)
Constructs a new CachedPreparedStatement.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBoolean(boolean value)
Adds a boolean parameter to the prepared statement.void
addInt(int value)
Adds an integer parameter to the prepared statement.void
addLong(long value)
Adds a long parameter to the prepared statement.void
addString(String value)
Adds a String parameter to the prepared statement.boolean
equals(Object object)
String
getSQL()
Returns the SQL.int
hashCode()
void
setParams(PreparedStatement pstmt)
Sets all parameters on the given PreparedStatement.void
setSQL(String sql)
Sets the SQL.String
toString()
-
-
-
Constructor Detail
-
CachedPreparedStatement
public CachedPreparedStatement()
Constructs a new CachedPreparedStatement.
-
CachedPreparedStatement
public CachedPreparedStatement(String sql)
Constructs a new CachedPreparedStatement.- Parameters:
sql
- the SQL.
-
-
Method Detail
-
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.
-
-