|
Rakesh API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.rakeshv.dbutils.StatementDecorator
org.rakeshv.dbutils.PreparedStatementDecorator
public class PreparedStatementDecorator
A decorator around a PreparedStatement to enable caching
and reuse of PreparedStatement objects. These work
only if the underlying Connection is kept open, as is
the case with connection pools or when using the ConnectionDecorator.
Copyright 2005 Rakesh Vidyadharan
| Field Summary | |
|---|---|
private java.sql.PreparedStatement |
statement
The PreparedStatement that this object decorates. |
protected Statistics |
statistics
Statistics for this statement. |
| Fields inherited from interface java.sql.Statement |
|---|
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO |
| Constructor Summary | |
|---|---|
protected |
PreparedStatementDecorator()
Default constructor. |
|
PreparedStatementDecorator(java.sql.PreparedStatement statement)
Create a new instance of the class using the specified PreparedStatement object that will be decorated. |
| Method Summary | |
|---|---|
void |
addBatch()
Adds a set of parameters to this PreparedStatement object's batch of commands. |
void |
clearParameters()
Clears the current parameter values immediately. |
void |
close()
Over-ridden to not close the getStatement(). |
boolean |
execute()
Executes the SQL statement in this PreparedStatement object, which may be any kind of SQL getStatement(). |
java.sql.ResultSet |
executeQuery()
Executes the SQL query in this PreparedStatement object and returns the ResultSet object generated by the query. |
int |
executeUpdate()
Executes the SQL statement in this PreparedStatement object, which must be an SQL INSERT, UPDATE or DELETE statement; or an SQL statement that returns nothing, such as a DDL getStatement(). |
java.sql.ResultSetMetaData |
getMetaData()
Retrieves a ResultSetMetaData object that contains information about the columns of the ResultSet object that will be returned when this PreparedStatement object is executed. |
java.sql.ParameterMetaData |
getParameterMetaData()
Retrieves the number, types and properties of this PreparedStatement object's parameters. |
java.sql.PreparedStatement |
getStatement()
Returns the statement object this class decorates. |
Statistics |
getStatistics()
Returns statistics. |
void |
setArray(int i,
java.sql.Array x)
Sets the designated parameter to the given Array object. |
void |
setAsciiStream(int parameterIndex,
java.io.InputStream x,
int length)
Sets the designated parameter to the given input stream, which will have the specified number of bytes. |
void |
setBigDecimal(int parameterIndex,
java.math.BigDecimal x)
Sets the designated parameter to the given java.math.BigDecimal value. |
void |
setBinaryStream(int parameterIndex,
java.io.InputStream x,
int length)
Sets the designated parameter to the given input stream, which will have the specified number of bytes. |
void |
setBlob(int i,
java.sql.Blob x)
Sets the designated parameter to the given Blob object. |
void |
setBoolean(int parameterIndex,
boolean x)
Sets the designated parameter to the given Java boolean value. |
void |
setByte(int parameterIndex,
byte x)
Sets the designated parameter to the given Java byte value. |
void |
setBytes(int parameterIndex,
byte[] x)
Sets the designated parameter to the given Java array of bytes. |
void |
setCharacterStream(int parameterIndex,
java.io.Reader reader,
int length)
Sets the designated parameter to the given Reader object, which is the given number of characters long. |
void |
setClob(int i,
java.sql.Clob x)
Sets the designated parameter to the given Clob object. |
void |
setDate(int parameterIndex,
java.sql.Date x)
Sets the designated parameter to the given java.sql.Date value. |
void |
setDate(int parameterIndex,
java.sql.Date x,
java.util.Calendar cal)
Sets the designated parameter to the given java.sql.Date value, using the given Calendar object. |
void |
setDouble(int parameterIndex,
double x)
Sets the designated parameter to the given Java double value. |
void |
setFloat(int parameterIndex,
float x)
Sets the designated parameter to the given Java float value. |
void |
setInt(int parameterIndex,
int x)
Sets the designated parameter to the given Java int value. |
void |
setLong(int parameterIndex,
long x)
Sets the designated parameter to the given Java long value. |
void |
setNull(int parameterIndex,
int sqlType)
Sets the designated parameter to SQL NULL. |
void |
setNull(int paramIndex,
int sqlType,
java.lang.String typeName)
Sets the designated parameter to SQL NULL. |
void |
setObject(int parameterIndex,
java.lang.Object x)
Sets the value of the designated parameter using the given object. |
void |
setObject(int parameterIndex,
java.lang.Object x,
int targetSqlType)
Sets the value of the designated parameter with the given object. |
void |
setObject(int parameterIndex,
java.lang.Object x,
int targetSqlType,
int scale)
Sets the value of the designated parameter with the given object. |
void |
setRef(int i,
java.sql.Ref x)
Sets the designated parameter to the given REF( |
void |
setShort(int parameterIndex,
short x)
Sets the designated parameter to the given Java short value. |
protected void |
setStatistics(Statistics statistics)
Set statistics. |
void |
setString(int parameterIndex,
java.lang.String x)
Sets the designated parameter to the given Java String value. |
void |
setTime(int parameterIndex,
java.sql.Time x)
Sets the designated parameter to the given java.sql.Time value. |
void |
setTime(int parameterIndex,
java.sql.Time x,
java.util.Calendar cal)
Sets the designated parameter to the given java.sql.Time value, using the given Calendar object. |
void |
setTimestamp(int parameterIndex,
java.sql.Timestamp x)
Sets the designated parameter to the given java.sql.Timestamp value. |
void |
setTimestamp(int parameterIndex,
java.sql.Timestamp x,
java.util.Calendar cal)
Sets the designated parameter to the given java.sql.Timestamp value, using the given Calendar object. |
void |
setUnicodeStream(int parameterIndex,
java.io.InputStream x,
int length)
Deprecated. |
void |
setURL(int parameterIndex,
java.net.URL x)
Sets the designated parameter to the given java.net.URL value. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface java.sql.Statement |
|---|
addBatch, cancel, clearBatch, clearWarnings, execute, execute, execute, execute, executeBatch, executeQuery, executeUpdate, executeUpdate, executeUpdate, executeUpdate, getConnection, getFetchDirection, getFetchSize, getGeneratedKeys, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setMaxFieldSize, setMaxRows, setQueryTimeout |
| Field Detail |
|---|
private java.sql.PreparedStatement statement
PreparedStatement that this object decorates.
protected Statistics statistics
| Constructor Detail |
|---|
protected PreparedStatementDecorator()
public PreparedStatementDecorator(java.sql.PreparedStatement statement)
statement - The PreparedStatement that is to be decorated.| Method Detail |
|---|
public java.sql.ResultSet executeQuery()
throws java.sql.SQLException
executeQuery in interface java.sql.PreparedStatementjava.sql.SQLException - If a database access error occurs or the SQL
statement does not return a ResultSet object
public int executeUpdate()
throws java.sql.SQLException
executeUpdate in interface java.sql.PreparedStatementjava.sql.SQLException - If a database access error occurs or the SQL
statement returns a ResultSet object
public void setNull(int parameterIndex,
int sqlType)
throws java.sql.SQLException
Note: You must specify the parameter's SQL type.
setNull in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...sqlType - The SQL type code defined in java.sql.Types
java.sql.SQLException - If a database access error occurs
public void setBoolean(int parameterIndex,
boolean x)
throws java.sql.SQLException
setBoolean in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - the parameter value
java.sql.SQLException - If a database access error occurs
public void setByte(int parameterIndex,
byte x)
throws java.sql.SQLException
setByte in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - The parameter value
java.sql.SQLException - If a database access error occurs
public void setShort(int parameterIndex,
short x)
throws java.sql.SQLException
setShort in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - the parameter value
java.sql.SQLException - If a database access error occurs
public void setInt(int parameterIndex,
int x)
throws java.sql.SQLException
setInt in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - The parameter value
java.sql.SQLException - If a database access error occurs
public void setLong(int parameterIndex,
long x)
throws java.sql.SQLException
setLong in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - The parameter value
java.sql.SQLException - If a database access error occurs
public void setFloat(int parameterIndex,
float x)
throws java.sql.SQLException
setFloat in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - The parameter value
java.sql.SQLException - If a database access error occurs
public void setDouble(int parameterIndex,
double x)
throws java.sql.SQLException
setDouble in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - the parameter value
java.sql.SQLException - If a database access error occurs
public void setBigDecimal(int parameterIndex,
java.math.BigDecimal x)
throws java.sql.SQLException
setBigDecimal in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - the parameter value
java.sql.SQLException - If a database access error occurs
public void setString(int parameterIndex,
java.lang.String x)
throws java.sql.SQLException
setString in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - the parameter value
java.sql.SQLException - If a database access error occurs
public void setBytes(int parameterIndex,
byte[] x)
throws java.sql.SQLException
setBytes in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - The parameter value
java.sql.SQLException - If a database access error occurs
public void setDate(int parameterIndex,
java.sql.Date x)
throws java.sql.SQLException
setDate in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - The parameter value
java.sql.SQLException - If a database access error occurs
public void setTime(int parameterIndex,
java.sql.Time x)
throws java.sql.SQLException
setTime in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - the parameter value
java.sql.SQLException - If a database access error occurs
public void setTimestamp(int parameterIndex,
java.sql.Timestamp x)
throws java.sql.SQLException
setTimestamp in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - The parameter value
java.sql.SQLException - If a database access error occurs
public void setAsciiStream(int parameterIndex,
java.io.InputStream x,
int length)
throws java.sql.SQLException
Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.
setAsciiStream in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - The Java input stream that contains the ASCII parameter valuelength - The number of bytes in the stream
java.sql.SQLException - If a database access error occurs
@Deprecated
public void setUnicodeStream(int parameterIndex,
java.io.InputStream x,
int length)
throws java.sql.SQLException
Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.
setUnicodeStream in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - A java.io.InputStream object that contains the Unicode
parameter value as two-byte Unicode characterslength - The number of bytes in the stream
java.sql.SQLException - If a database access error occurs
public void setBinaryStream(int parameterIndex,
java.io.InputStream x,
int length)
throws java.sql.SQLException
Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.
setBinaryStream in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - The java input stream which contains the binary parameter valuelength - The number of bytes in the stream
java.sql.SQLException - If a database access error occurs
public void clearParameters()
throws java.sql.SQLException
In general, parameter values remain in force for repeated use of a getStatement(). Setting a parameter value automatically clears its previous value. However, in some cases it is useful to immediately release the resources used by the current parameter values; this can be done by calling the method clearParameters.
clearParameters in interface java.sql.PreparedStatementjava.sql.SQLException - If a database access error occurs
public void setObject(int parameterIndex,
java.lang.Object x,
int targetSqlType,
int scale)
throws java.sql.SQLException
The given Java object will be converted to the given targetSqlType before being sent to the database. If the object has a custom mapping (is of a class implementing the interface SQLData), the JDBC driver should call the method SQLData.writeSQL to write it to the SQL data stream. If, on the other hand, the object is of a class implementing Ref, Blob, Clob, Struct, or Array, the driver should pass it to the database as a value of the corresponding SQL type.
Note that this method may be used to pass database-specific abstract data types.
setObject in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - The object containing the input parameter valuetargetSqlType - The SQL type (as defined in java.sql.Types)
to be sent to the database. The scale argument may further
qualify this type.scale - For java.sql.Types.DECIMAL or java.sql.Types.NUMERIC
types, this is the number of digits after the decimal point. For
all other types, this value will be ignored.
java.sql.SQLException - If a database access error occurs
public void setObject(int parameterIndex,
java.lang.Object x,
int targetSqlType)
throws java.sql.SQLException
setObject in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - The object containing the input parameter valuetargetSqlType - The SQL type (as defined in java.sql.Types)
to be sent to the database
java.sql.SQLException - If a database access error occurs
public void setObject(int parameterIndex,
java.lang.Object x)
throws java.sql.SQLException
The JDBC specification specifies a standard mapping from Java Object types to SQL types. The given argument will be converted to the corresponding SQL type before being sent to the database.
Note that this method may be used to pass datatabase- specific abstract data types, by using a driver-specific Java type. If the object is of a class implementing the interface SQLData, the JDBC driver should call the method SQLData.writeSQL to write it to the SQL data stream. If, on the other hand, the object is of a class implementing Ref, Blob, Clob, Struct, or Array, the driver should pass it to the database as a value of the corresponding SQL type.
This method throws an exception if there is an ambiguity, for example, if the object is of a class implementing more than one of the interfaces named above.
setObject in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - The object containing the input parameter value
java.sql.SQLException - If a database access error occurs or the type
of the given object is ambiguous
public boolean execute()
throws java.sql.SQLException
The execute method returns a boolean to indicate the form of the first result. You must call either the method getResultSet or getUpdateCount to retrieve the result; you must call getMoreResults to move to any subsequent result(s).
execute in interface java.sql.PreparedStatementtrue if the first result is a
ResultSet object; false if the first result is an update count
or there is no result
java.sql.SQLException - If a database access error occurs or an
argument is supplied to this method
public void addBatch()
throws java.sql.SQLException
addBatch in interface java.sql.PreparedStatementjava.sql.SQLException - If a database access error occurs
public void setCharacterStream(int parameterIndex,
java.io.Reader reader,
int length)
throws java.sql.SQLException
Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.
setCharacterStream in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...reader - The java.io.Reader object that contains the Unicode
datalength - The number of characters in the stream
java.sql.SQLException - If a database access error occurs
public void setRef(int i,
java.sql.Ref x)
throws java.sql.SQLException
setRef in interface java.sql.PreparedStatementi - The first parameter is 1, the second is 2, ...x - An SQL REF value
java.sql.SQLException - If a database access error occurs
public void setBlob(int i,
java.sql.Blob x)
throws java.sql.SQLException
setBlob in interface java.sql.PreparedStatementi - The first parameter is 1, the second is 2, ...x - A Blob object that maps an SQL BLOB value
java.sql.SQLException - If a database access error occurs
public void setClob(int i,
java.sql.Clob x)
throws java.sql.SQLException
setClob in interface java.sql.PreparedStatementi - The first parameter is 1, the second is 2, ...x - A Clob object that maps an SQL CLOB value
java.sql.SQLException - If a database access error occurs
public void setArray(int i,
java.sql.Array x)
throws java.sql.SQLException
setArray in interface java.sql.PreparedStatementi - The first parameter is 1, the second is 2, ...x - An Array object that maps an SQL ARRAY value
java.sql.SQLException - If a database access error occurs
public java.sql.ResultSetMetaData getMetaData()
throws java.sql.SQLException
Because a PreparedStatement object is precompiled, it is
possible to know about the ResultSet object that it will return
without having to execute it. Consequently, it is possible to
invoke the method getMetaData on a PreparedStatement object rather
than waiting to execute it and then invoking the
ResultSet.getMetaData method on the ResultSet object
that is returned.
NOTE: Using this method may be expensive for some drivers due to the lack of underlying DBMS support.
getMetaData in interface java.sql.PreparedStatementjava.sql.SQLException - If a database access error occurs
public void setDate(int parameterIndex,
java.sql.Date x,
java.util.Calendar cal)
throws java.sql.SQLException
setDate in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - The parameter valuecal - The Calendar object the driver will use to construct
the date
java.sql.SQLException - If a database access error occurs
public void setTime(int parameterIndex,
java.sql.Time x,
java.util.Calendar cal)
throws java.sql.SQLException
setTime in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - The parameter valuecal - The Calendar object the driver will use to construct
the time
java.sql.SQLException - If a database access error occurs
public void setTimestamp(int parameterIndex,
java.sql.Timestamp x,
java.util.Calendar cal)
throws java.sql.SQLException
setTimestamp in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - The parameter valuecal - The Calendar object the driver will use to construct
the timestamp
java.sql.SQLException - If a database access error occurs
public void setNull(int paramIndex,
int sqlType,
java.lang.String typeName)
throws java.sql.SQLException
Note: To be portable, applications must give the SQL type code and the fully-qualified SQL type name when specifying a NULL user-defined or REF parameter. In the case of a user-defined type the name is the type name of the parameter itself. For a REF parameter, the name is the type name of the referenced type. If a JDBC driver does not need the type code or type name information, it may ignore it. Although it is intended for user-defined and Ref parameters, this method may be used to set a null parameter of any JDBC type. If the parameter does not have a user-defined or REF type, the given typeName is ignored.
setNull in interface java.sql.PreparedStatementparamIndex - - The first parameter is 1, the second is 2, ...sqlType - A value from java.sql.TypestypeName - The fully-qualified name of an SQL user-defined
type; ignored if the parameter is not a user-defined type or REF
java.sql.SQLException - If a database access error occurs
public void setURL(int parameterIndex,
java.net.URL x)
throws java.sql.SQLException
setURL in interface java.sql.PreparedStatementparameterIndex - The first parameter is 1, the second is 2, ...x - The java.net.URL object to be set
java.sql.SQLException - If a database access error occurs
public java.sql.ParameterMetaData getParameterMetaData()
throws java.sql.SQLException
getParameterMetaData in interface java.sql.PreparedStatementjava.sql.SQLException - If a database access error occurs
public void close()
throws java.sql.SQLException
clearParameters().
close in interface java.sql.Statementclose in class StatementDecoratorjava.sql.SQLException - If a database access error occurspublic java.sql.PreparedStatement getStatement()
statement object this class decorates.
getStatement in class StatementDecoratorpublic final Statistics getStatistics()
statistics.
protected final void setStatistics(Statistics statistics)
statistics.
statistics - The value to set.
|
Rakesh API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||