Package org.jivesoftware.database
Class CachedPreparedStatement
java.lang.Object
org.jivesoftware.database.CachedPreparedStatement
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 Summary
ConstructorsConstructorDescriptionConstructs a new CachedPreparedStatement.Constructs a new CachedPreparedStatement. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
Adds a String parameter to the prepared statement.boolean
getSQL()
Returns the SQL.int
hashCode()
void
setParams
(PreparedStatement pstmt) Sets all parameters on the given PreparedStatement.void
Sets the SQL.toString()
-
Constructor Details
-
CachedPreparedStatement
public CachedPreparedStatement()Constructs a new CachedPreparedStatement. -
CachedPreparedStatement
Constructs a new CachedPreparedStatement.- Parameters:
sql
- the SQL.
-
-
Method Details
-
getSQL
Returns the SQL.- Returns:
- the SQL.
-
setSQL
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
Adds a String parameter to the prepared statement.- Parameters:
value
- the String value.
-
setParams
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
-
hashCode
public int hashCode() -
toString
-