Class BrokeredPreparedStatement
- All Implemented Interfaces:
AutoCloseable, PreparedStatement, Statement, Wrapper, EnginePreparedStatement, EngineStatement
- Direct Known Subclasses:
BrokeredCallableStatement, BrokeredPreparedStatement42
PreparedStatement that forwards calls off to a real
PreparedStatement obtained through the
BrokeredStatementControl.getRealPreparedStatement() method.
This class implements the JDBC 4.1 interface.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ObjectAn Integer, an int array or a String array that specifies generated key columns, or null if there are no generated key columns.(package private) final StringSQL used to create me.Fields inherited from class BrokeredStatement
control, resultSetConcurrency, resultSetHoldability, resultSetTypeFields inherited from interface Statement
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO -
Constructor Summary
ConstructorsConstructorDescriptionBrokeredPreparedStatement(BrokeredStatementControl control, String sql, Object generatedKeys) -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddBatch()JDBC 2.0 Add a set of parameters to the batch.final voidIn general, parameter values remain in force for repeated use of a Statement.voidclose()In many cases, it is desirable to immediately release a Statements's database and JDBC resources instead of waiting for this to happen when it is automatically closed; the close method provides this immediate release.createDuplicateStatement(Connection conn, PreparedStatement oldStatement) Create a duplicate PreparedStatement to this, including state, from the passed in Connection.final booleanexecute()long/////////////////////////////////////////////////////////////////final ResultSetA prepared SQL query is executed and its ResultSet is returned.final intExecute a SQL INSERT, UPDATE or DELETE statement.final ResultSetMetaDataJDBC 2.0 The number, types and properties of a ResultSet's columns are provided by the getMetaData method.final ParameterMetaData(package private) PreparedStatementAccess the underlying PreparedStatement.final StatementOverride the BrokeredStatement's getStatement() to always return a PreparedStatement.final longGet the version of the prepared statement.final voidfinal voidsetAsciiStream(int parameterIndex, InputStream x) Sets the designated parameter to the given input stream.final voidsetAsciiStream(int parameterIndex, InputStream x, int length) We do this inefficiently and read it all in here.final voidsetAsciiStream(int parameterIndex, InputStream x, long length) Sets the designated parameter to the given input stream, which will have the specified number of bytes.final voidsetBigDecimal(int parameterIndex, BigDecimal x) Set a parameter to a java.math.BigDecimal value.voidsetBinaryStream(int parameterIndex, InputStream x) final voidsetBinaryStream(int parameterIndex, InputStream x, int length) final voidsetBinaryStream(int parameterIndex, InputStream x, long length) Sets the designated parameter to the given input stream, which will have the specified number of bytes.final voidsetBlob(int parameterIndex, InputStream inputStream) Sets the designated parameter to aInputStreamobject.final voidsetBlob(int parameterIndex, InputStream inputStream, long length) final voidfinal voidsetBoolean(int parameterIndex, boolean x) Set a parameter to a Java boolean value.final voidsetByte(int parameterIndex, byte x) Set a parameter to a Java byte value.final voidsetBytes(int parameterIndex, byte[] x) Set a parameter to a Java array of bytes.voidsetCharacterStream(int parameterIndex, Reader reader) final voidsetCharacterStream(int parameterIndex, Reader reader, int length) final voidsetCharacterStream(int parameterIndex, Reader x, long length) Sets the designated parameter to the given Reader, which will have the specified number of bytes.final voidSets the designated parameter to aReaderobject.final voidfinal voidfinal voidSet a parameter to a java.sql.Date value.final voidfinal voidsetDouble(int parameterIndex, double x) Set a parameter to a Java double value.final voidsetFloat(int parameterIndex, float x) Set a parameter to a Java float value.final voidsetInt(int parameterIndex, int x) Set a parameter to a Java int value.final voidsetLong(int parameterIndex, long x) Set a parameter to a Java long value.final voidsetNCharacterStream(int parameterIndex, Reader value) final voidsetNCharacterStream(int index, Reader value, long length) final voidfinal voidfinal voidfinal voidsetNString(int index, String value) final voidsetNull(int parameterIndex, int sqlType) Set a parameter to SQL NULL.final voidSet a parameter to SQL NULL.final voidSet the value of a parameter using an object; use the java.lang equivalent objects for integral values.final voidThis method is like setObject above, but assumes a scale of zero.final voidThe interface says that the type of the Object parameter must be compatible with the type of the targetSqlType.final voidfinal voidfinal voidsetShort(int parameterIndex, short x) Set a parameter to a Java short value.final voidfinal voidSet a parameter to a Java String value.final voidSet a parameter to a java.sql.Time value.final voidfinal voidsetTimestamp(int parameterIndex, Timestamp x) Set a parameter to a java.sql.Timestamp value.final voidsetTimestamp(int i, Timestamp x, Calendar cal) final voidsetUnicodeStream(int parameterIndex, InputStream x, int length) Deprecated.final voidMethods inherited from class BrokeredStatement
addBatch, cancel, checkIfClosed, clearBatch, clearWarnings, closeOnCompletion, controlCheck, createDuplicateStatement, execute, execute, execute, execute, executeBatch, executeLargeBatch, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeQuery, executeUpdate, executeUpdate, executeUpdate, executeUpdate, getConnection, getFetchDirection, getFetchSize, getGeneratedKeys, getLargeMaxRows, getLargeUpdateCount, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, isClosed, isCloseOnCompletion, isPoolable, isWrapperFor, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setLargeMaxRows, setMaxFieldSize, setMaxRows, setPoolable, setQueryTimeout, setStatementState, unableToUnwrap, unwrap, wrapResultSetMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface EngineStatement
closeOnCompletion, executeLargeBatch, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, getLargeMaxRows, getLargeUpdateCount, isCloseOnCompletion, setLargeMaxRowsMethods inherited from interface PreparedStatement
setObject, setObjectMethods inherited from interface Statement
addBatch, cancel, clearBatch, clearWarnings, enquoteIdentifier, enquoteLiteral, enquoteNCharLiteral, 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, isClosed, isPoolable, isSimpleIdentifier, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setMaxFieldSize, setMaxRows, setPoolable, setQueryTimeoutMethods inherited from interface Wrapper
isWrapperFor, unwrap
-
Field Details
-
sql
SQL used to create me. -
generatedKeys
An Integer, an int array or a String array that specifies generated key columns, or null if there are no generated key columns.
-
-
Constructor Details
-
BrokeredPreparedStatement
public BrokeredPreparedStatement(BrokeredStatementControl control, String sql, Object generatedKeys) throws SQLException - Throws:
SQLException
-
-
Method Details
-
executeQuery
A prepared SQL query is executed and its ResultSet is returned.- Specified by:
executeQueryin interfacePreparedStatement- Returns:
- a ResultSet that contains the data produced by the query; never null
- Throws:
SQLException- thrown on failure.
-
executeUpdate
Execute a SQL INSERT, UPDATE or DELETE statement. In addition, SQL statements that return nothing such as SQL DDL statements can be executed.- Specified by:
executeUpdatein interfacePreparedStatement- Returns:
- either the row count for INSERT, UPDATE or DELETE; or 0 for SQL statements that return nothing
- Throws:
SQLException- thrown on failure.
-
close
Description copied from class:BrokeredStatementIn many cases, it is desirable to immediately release a Statements's database and JDBC resources instead of waiting for this to happen when it is automatically closed; the close method provides this immediate release.Note: A Statement is automatically closed when it is garbage collected. When a Statement is closed its current ResultSet, if one exists, is also closed.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceStatement- Overrides:
closein classBrokeredStatement- Throws:
SQLException- thrown on failure.
-
setNull
Set a parameter to SQL NULL.Note: You must specify the parameter's SQL type.
- Specified by:
setNullin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...sqlType- SQL type code defined by java.sql.Types- Throws:
SQLException- thrown on failure.
-
setNull
Set a parameter to SQL NULL.Note: You must specify the parameter's SQL type.
- Specified by:
setNullin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...sqlType- SQL type code defined by java.sql.Types- Throws:
SQLException- thrown on failure.
-
setBoolean
Set a parameter to a Java boolean value. According to the JDBC API spec, the driver converts this to a SQL BIT value when it sends it to the database. But we don't have to do this, since the database engine supports a boolean type.- Specified by:
setBooleanin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- thrown on failure.
-
setByte
Set a parameter to a Java byte value. The driver converts this to a SQL TINYINT value when it sends it to the database.- Specified by:
setBytein interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- thrown on failure.
-
setShort
Set a parameter to a Java short value. The driver converts this to a SQL SMALLINT value when it sends it to the database.- Specified by:
setShortin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- thrown on failure.
-
setInt
Set a parameter to a Java int value. The driver converts this to a SQL INTEGER value when it sends it to the database.- Specified by:
setIntin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- thrown on failure.
-
setLong
Set a parameter to a Java long value. The driver converts this to a SQL BIGINT value when it sends it to the database.- Specified by:
setLongin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- thrown on failure.
-
setFloat
Set a parameter to a Java float value. The driver converts this to a SQL FLOAT value when it sends it to the database.- Specified by:
setFloatin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- thrown on failure.
-
setDouble
Set a parameter to a Java double value. The driver converts this to a SQL DOUBLE value when it sends it to the database.- Specified by:
setDoublein interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- thrown on failure.
-
setBigDecimal
Set a parameter to a java.math.BigDecimal value. The driver converts this to a SQL NUMERIC value when it sends it to the database.- Specified by:
setBigDecimalin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- thrown on failure.
-
setString
Set a parameter to a Java String value. The driver converts this to a SQL VARCHAR or LONGVARCHAR value (depending on the arguments size relative to the driver's limits on VARCHARs) when it sends it to the database.- Specified by:
setStringin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- thrown on failure.
-
setBytes
Set a parameter to a Java array of bytes. The driver converts this to a SQL VARBINARY or LONGVARBINARY (depending on the argument's size relative to the driver's limits on VARBINARYs) when it sends it to the database.- Specified by:
setBytesin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- thrown on failure.
-
setDate
Set a parameter to a java.sql.Date value. The driver converts this to a SQL DATE value when it sends it to the database.- Specified by:
setDatein interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- thrown on failure.
-
setTime
Set a parameter to a java.sql.Time value. The driver converts this to a SQL TIME value when it sends it to the database.- Specified by:
setTimein interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- thrown on failure.
-
setTimestamp
Set a parameter to a java.sql.Timestamp value. The driver converts this to a SQL TIMESTAMP value when it sends it to the database.- Specified by:
setTimestampin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter value- Throws:
SQLException- thrown on failure.
-
setAsciiStream
We do this inefficiently and read it all in here. The target type is assumed to be a String.- Specified by:
setAsciiStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the java input stream which contains the ASCII parameter valuelength- the number of bytes in the stream- Throws:
SQLException- thrown on failure.
-
setUnicodeStream
public final void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException Deprecated.We do this inefficiently and read it all in here. The target type is assumed to be a String. The unicode source is assumed to be in char[]. RESOLVE: might it be in UTF, instead? that'd be faster!- Specified by:
setUnicodeStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the java input stream which contains the UNICODE parameter valuelength- the number of bytes in the stream- Throws:
SQLException- thrown on failure.
-
setBinaryStream
public final void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException - Specified by:
setBinaryStreamin interfacePreparedStatement- Parameters:
parameterIndex- 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- Throws:
SQLException- thrown on failure.
-
addBatch
JDBC 2.0 Add a set of parameters to the batch.- Specified by:
addBatchin interfacePreparedStatement- Throws:
SQLException- if a database-access error occurs.
-
clearParameters
In general, parameter values remain in force for repeated use of a Statement. 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 clearParameters.
- Specified by:
clearParametersin interfacePreparedStatement- Throws:
SQLException- thrown on failure.
-
getMetaData
JDBC 2.0 The number, types and properties of a ResultSet's columns are provided by the getMetaData method.- Specified by:
getMetaDatain interfacePreparedStatement- Returns:
- the description of a ResultSet's columns
- Throws:
SQLException- Feature not implemented for now.
-
setObject
public final void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException The interface says that the type of the Object parameter must be compatible with the type of the targetSqlType. We check that, and if it flies, we expect the underlying engine to do the required conversion once we pass in the value using its type. So, an Integer converting to a CHAR is done via setInteger() support on the underlying CHAR type.If x is null, it won't tell us its type, so we pass it on to setNull
- Specified by:
setObjectin interfacePreparedStatement- Parameters:
parameterIndex- 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. For all other types this value will be ignored,- Throws:
SQLException- thrown on failure.
-
setObject
This method is like setObject above, but assumes a scale of zero.- Specified by:
setObjectin interfacePreparedStatement- Throws:
SQLException- thrown on failure.
-
setObject
Set the value of a parameter using an object; use the java.lang equivalent objects for integral values.
The JDBC specification specifies a standard mapping from Java Object types to SQL types. The given argument java object 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.
- Specified by:
setObjectin interfacePreparedStatement- Parameters:
parameterIndex- The first parameter is 1, the second is 2, ...x- The object containing the input parameter value- Throws:
SQLException- thrown on failure.
-
execute
- Specified by:
executein interfacePreparedStatement- Throws:
SQLException- thrown on failure.- See Also:
-
setCharacterStream
public final void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException - Specified by:
setCharacterStreamin interfacePreparedStatement- Throws:
SQLException
-
setRef
- Specified by:
setRefin interfacePreparedStatement- Throws:
SQLException
-
setBlob
- Specified by:
setBlobin interfacePreparedStatement- Throws:
SQLException
-
setClob
- Specified by:
setClobin interfacePreparedStatement- Throws:
SQLException
-
setArray
- Specified by:
setArrayin interfacePreparedStatement- Throws:
SQLException
-
setDate
- Specified by:
setDatein interfacePreparedStatement- Throws:
SQLException
-
setTime
- Specified by:
setTimein interfacePreparedStatement- Throws:
SQLException
-
setTimestamp
- Specified by:
setTimestampin interfacePreparedStatement- Throws:
SQLException
-
executeLargeUpdate
Description copied from interface:EnginePreparedStatement/////////////////////////////////////////////////////////////////- Specified by:
executeLargeUpdatein interfaceEnginePreparedStatement- Specified by:
executeLargeUpdatein interfacePreparedStatement- Throws:
SQLException
-
setBinaryStream
- Specified by:
setBinaryStreamin interfacePreparedStatement- Throws:
SQLException
-
setCharacterStream
- Specified by:
setCharacterStreamin interfacePreparedStatement- Throws:
SQLException
-
setURL
- Specified by:
setURLin interfacePreparedStatement- Throws:
SQLException
-
getParameterMetaData
- Specified by:
getParameterMetaDatain interfacePreparedStatement- Throws:
SQLException
-
setRowId
- Specified by:
setRowIdin interfacePreparedStatement- Throws:
SQLException
-
setNString
- Specified by:
setNStringin interfacePreparedStatement- Throws:
SQLException
-
setNCharacterStream
- Specified by:
setNCharacterStreamin interfacePreparedStatement- Throws:
SQLException
-
setNCharacterStream
- Specified by:
setNCharacterStreamin interfacePreparedStatement- Throws:
SQLException
-
setNClob
- Specified by:
setNClobin interfacePreparedStatement- Throws:
SQLException
-
setClob
- Specified by:
setClobin interfacePreparedStatement- Throws:
SQLException
-
setBlob
public final void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException - Specified by:
setBlobin interfacePreparedStatement- Throws:
SQLException
-
setNClob
- Specified by:
setNClobin interfacePreparedStatement- Throws:
SQLException
-
setNClob
- Specified by:
setNClobin interfacePreparedStatement- Throws:
SQLException
-
setSQLXML
- Specified by:
setSQLXMLin interfacePreparedStatement- Throws:
SQLException
-
setAsciiStream
Sets the designated parameter to the given input stream.- Specified by:
setAsciiStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the Java input stream that contains the ASCII parameter value- Throws:
SQLException- if a database access error occurs or this method is called on a closedPreparedStatement
-
setAsciiStream
public final void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException Sets the designated parameter to the given input stream, which will have the specified number of bytes.- Specified by:
setAsciiStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the java input stream which contains the ASCII parameter valuelength- the number of bytes in the stream- Throws:
SQLException- thrown on failure.
-
setBinaryStream
public final void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException Sets the designated parameter to the given input stream, which will have the specified number of bytes.- Specified by:
setBinaryStreamin interfacePreparedStatement- Parameters:
parameterIndex- 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- Throws:
SQLException- thrown on failure.
-
setBlob
Sets the designated parameter to aInputStreamobject. This method differs from thesetBinaryStream(int, InputStream)method because it informs the driver that the parameter value should be sent to the server as aBLOB.- Specified by:
setBlobin interfacePreparedStatement- Parameters:
inputStream- an object that contains the data to set the parameter value to.- Throws:
SQLException- if a database access error occurs, this method is called on a closedPreparedStatement
-
setCharacterStream
Sets the designated parameter to the given Reader, which will have the specified number of bytes.- Specified by:
setCharacterStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the java Reader which contains the UNICODE valuelength- the number of bytes in the stream- Throws:
SQLException- thrown on failure.
-
setClob
Sets the designated parameter to aReaderobject. This method differs from thesetCharacterStream(int,Reader)method because it informs the driver that the parameter value should be sent to the server as aCLOB.- Specified by:
setClobin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...reader- an object that contains the data to set the parameter value to.- Throws:
SQLException- if a database access error occurs, this method is called on a closed PreparedStatement
-
getPreparedStatement
Access the underlying PreparedStatement. This method is package protected to restrict access to the underlying object to the brokered objects. Allowing the application to access the underlying object thtough a public method would- Throws:
SQLException
-
getStatement
Override the BrokeredStatement's getStatement() to always return a PreparedStatement.- Overrides:
getStatementin classBrokeredStatement- Throws:
SQLException
-
createDuplicateStatement
public PreparedStatement createDuplicateStatement(Connection conn, PreparedStatement oldStatement) throws SQLException Create a duplicate PreparedStatement to this, including state, from the passed in Connection.- Throws:
SQLException
-
getVersionCounter
Description copied from interface:EnginePreparedStatementGet the version of the prepared statement. If this has not been changed, the caller may assume that a recompilation has not taken place, i.e. meta-data are (also) unchanged.- Specified by:
getVersionCounterin interfaceEnginePreparedStatement- Returns:
- version counter
- Throws:
SQLException
-