Class BrokeredPreparedStatement

java.lang.Object
org.apache.derby.iapi.jdbc.BrokeredStatement
org.apache.derby.iapi.jdbc.BrokeredPreparedStatement
All Implemented Interfaces:
AutoCloseable, PreparedStatement, Statement, Wrapper, EnginePreparedStatement, EngineStatement
Direct Known Subclasses:
BrokeredCallableStatement, BrokeredPreparedStatement42

public class BrokeredPreparedStatement extends BrokeredStatement implements EnginePreparedStatement
A brokered PreparedStatement that forwards calls off to a real PreparedStatement obtained through the BrokeredStatementControl.getRealPreparedStatement() method. This class implements the JDBC 4.1 interface.
  • Field Details

    • sql

      final String sql
      SQL used to create me.
    • generatedKeys

      private final Object 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

  • Method Details

    • executeQuery

      public final ResultSet executeQuery() throws SQLException
      A prepared SQL query is executed and its ResultSet is returned.
      Specified by:
      executeQuery in interface PreparedStatement
      Returns:
      a ResultSet that contains the data produced by the query; never null
      Throws:
      SQLException - thrown on failure.
    • executeUpdate

      public final int executeUpdate() throws SQLException
      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:
      executeUpdate in interface PreparedStatement
      Returns:
      either the row count for INSERT, UPDATE or DELETE; or 0 for SQL statements that return nothing
      Throws:
      SQLException - thrown on failure.
    • close

      public void close() throws SQLException
      Description copied from class: BrokeredStatement
      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.

      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:
      close in interface AutoCloseable
      Specified by:
      close in interface Statement
      Overrides:
      close in class BrokeredStatement
      Throws:
      SQLException - thrown on failure.
    • setNull

      public final void setNull(int parameterIndex, int sqlType) throws SQLException
      Set a parameter to SQL NULL.

      Note: You must specify the parameter's SQL type.

      Specified by:
      setNull in interface PreparedStatement
      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

      public final void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException
      Set a parameter to SQL NULL.

      Note: You must specify the parameter's SQL type.

      Specified by:
      setNull in interface PreparedStatement
      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

      public final void setBoolean(int parameterIndex, boolean x) throws SQLException
      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:
      setBoolean in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      SQLException - thrown on failure.
    • setByte

      public final void setByte(int parameterIndex, byte x) throws SQLException
      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:
      setByte in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      SQLException - thrown on failure.
    • setShort

      public final void setShort(int parameterIndex, short x) throws SQLException
      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:
      setShort in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      SQLException - thrown on failure.
    • setInt

      public final void setInt(int parameterIndex, int x) throws SQLException
      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:
      setInt in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      SQLException - thrown on failure.
    • setLong

      public final void setLong(int parameterIndex, long x) throws SQLException
      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:
      setLong in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      SQLException - thrown on failure.
    • setFloat

      public final void setFloat(int parameterIndex, float x) throws SQLException
      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:
      setFloat in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      SQLException - thrown on failure.
    • setDouble

      public final void setDouble(int parameterIndex, double x) throws SQLException
      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:
      setDouble in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      SQLException - thrown on failure.
    • setBigDecimal

      public final void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException
      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:
      setBigDecimal in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      SQLException - thrown on failure.
    • setString

      public final void setString(int parameterIndex, String x) throws SQLException
      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:
      setString in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      SQLException - thrown on failure.
    • setBytes

      public final void setBytes(int parameterIndex, byte[] x) throws SQLException
      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:
      setBytes in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      SQLException - thrown on failure.
    • setDate

      public final void setDate(int parameterIndex, Date x) throws SQLException
      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:
      setDate in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      SQLException - thrown on failure.
    • setTime

      public final void setTime(int parameterIndex, Time x) throws SQLException
      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:
      setTime in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      SQLException - thrown on failure.
    • setTimestamp

      public final void setTimestamp(int parameterIndex, Timestamp x) throws SQLException
      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:
      setTimestamp in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      Throws:
      SQLException - thrown on failure.
    • setAsciiStream

      public final void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException
      We do this inefficiently and read it all in here. The target type is assumed to be a String.
      Specified by:
      setAsciiStream in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the java input stream which contains the ASCII parameter value
      length - 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:
      setUnicodeStream in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the java input stream which contains the UNICODE parameter value
      length - 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:
      setBinaryStream in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the java input stream which contains the binary parameter value
      length - the number of bytes in the stream
      Throws:
      SQLException - thrown on failure.
    • addBatch

      public final void addBatch() throws SQLException
      JDBC 2.0 Add a set of parameters to the batch.
      Specified by:
      addBatch in interface PreparedStatement
      Throws:
      SQLException - if a database-access error occurs.
    • clearParameters

      public final void clearParameters() throws SQLException

      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:
      clearParameters in interface PreparedStatement
      Throws:
      SQLException - thrown on failure.
    • getMetaData

      public final ResultSetMetaData getMetaData() throws SQLException
      JDBC 2.0 The number, types and properties of a ResultSet's columns are provided by the getMetaData method.
      Specified by:
      getMetaData in interface PreparedStatement
      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:
      setObject in interface PreparedStatement
      Parameters:
      parameterIndex - The first parameter is 1, the second is 2, ...
      x - The object containing the input parameter value
      targetSqlType - 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

      public final void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException
      This method is like setObject above, but assumes a scale of zero.
      Specified by:
      setObject in interface PreparedStatement
      Throws:
      SQLException - thrown on failure.
    • setObject

      public final void setObject(int parameterIndex, Object x) throws SQLException

      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:
      setObject in interface PreparedStatement
      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

      public final boolean execute() throws SQLException
      Specified by:
      execute in interface PreparedStatement
      Throws:
      SQLException - thrown on failure.
      See Also:
    • setCharacterStream

      public final void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException
      Specified by:
      setCharacterStream in interface PreparedStatement
      Throws:
      SQLException
    • setRef

      public final void setRef(int i, Ref x) throws SQLException
      Specified by:
      setRef in interface PreparedStatement
      Throws:
      SQLException
    • setBlob

      public final void setBlob(int i, Blob x) throws SQLException
      Specified by:
      setBlob in interface PreparedStatement
      Throws:
      SQLException
    • setClob

      public final void setClob(int i, Clob x) throws SQLException
      Specified by:
      setClob in interface PreparedStatement
      Throws:
      SQLException
    • setArray

      public final void setArray(int i, Array x) throws SQLException
      Specified by:
      setArray in interface PreparedStatement
      Throws:
      SQLException
    • setDate

      public final void setDate(int i, Date x, Calendar cal) throws SQLException
      Specified by:
      setDate in interface PreparedStatement
      Throws:
      SQLException
    • setTime

      public final void setTime(int i, Time x, Calendar cal) throws SQLException
      Specified by:
      setTime in interface PreparedStatement
      Throws:
      SQLException
    • setTimestamp

      public final void setTimestamp(int i, Timestamp x, Calendar cal) throws SQLException
      Specified by:
      setTimestamp in interface PreparedStatement
      Throws:
      SQLException
    • executeLargeUpdate

      public long executeLargeUpdate() throws SQLException
      Specified by:
      executeLargeUpdate in interface EnginePreparedStatement
      Specified by:
      executeLargeUpdate in interface PreparedStatement
      Throws:
      SQLException
    • setBinaryStream

      public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException
      Specified by:
      setBinaryStream in interface PreparedStatement
      Throws:
      SQLException
    • setCharacterStream

      public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException
      Specified by:
      setCharacterStream in interface PreparedStatement
      Throws:
      SQLException
    • setURL

      public final void setURL(int i, URL x) throws SQLException
      Specified by:
      setURL in interface PreparedStatement
      Throws:
      SQLException
    • getParameterMetaData

      public final ParameterMetaData getParameterMetaData() throws SQLException
      Specified by:
      getParameterMetaData in interface PreparedStatement
      Throws:
      SQLException
    • setRowId

      public final void setRowId(int parameterIndex, RowId x) throws SQLException
      Specified by:
      setRowId in interface PreparedStatement
      Throws:
      SQLException
    • setNString

      public final void setNString(int index, String value) throws SQLException
      Specified by:
      setNString in interface PreparedStatement
      Throws:
      SQLException
    • setNCharacterStream

      public final void setNCharacterStream(int parameterIndex, Reader value) throws SQLException
      Specified by:
      setNCharacterStream in interface PreparedStatement
      Throws:
      SQLException
    • setNCharacterStream

      public final void setNCharacterStream(int index, Reader value, long length) throws SQLException
      Specified by:
      setNCharacterStream in interface PreparedStatement
      Throws:
      SQLException
    • setNClob

      public final void setNClob(int index, NClob value) throws SQLException
      Specified by:
      setNClob in interface PreparedStatement
      Throws:
      SQLException
    • setClob

      public final void setClob(int parameterIndex, Reader reader, long length) throws SQLException
      Specified by:
      setClob in interface PreparedStatement
      Throws:
      SQLException
    • setBlob

      public final void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException
      Specified by:
      setBlob in interface PreparedStatement
      Throws:
      SQLException
    • setNClob

      public final void setNClob(int parameterIndex, Reader reader) throws SQLException
      Specified by:
      setNClob in interface PreparedStatement
      Throws:
      SQLException
    • setNClob

      public final void setNClob(int parameterIndex, Reader reader, long length) throws SQLException
      Specified by:
      setNClob in interface PreparedStatement
      Throws:
      SQLException
    • setSQLXML

      public final void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException
      Specified by:
      setSQLXML in interface PreparedStatement
      Throws:
      SQLException
    • setAsciiStream

      public final void setAsciiStream(int parameterIndex, InputStream x) throws SQLException
      Sets the designated parameter to the given input stream.
      Specified by:
      setAsciiStream in interface PreparedStatement
      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 closed PreparedStatement
    • 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:
      setAsciiStream in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the java input stream which contains the ASCII parameter value
      length - 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:
      setBinaryStream in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the java input stream which contains the binary parameter value
      length - the number of bytes in the stream
      Throws:
      SQLException - thrown on failure.
    • setBlob

      public final void setBlob(int parameterIndex, InputStream inputStream) throws SQLException
      Sets the designated parameter to a InputStream object. This method differs from the setBinaryStream(int, InputStream) method because it informs the driver that the parameter value should be sent to the server as a BLOB.
      Specified by:
      setBlob in interface PreparedStatement
      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 closed PreparedStatement
    • setCharacterStream

      public final void setCharacterStream(int parameterIndex, Reader x, long length) throws SQLException
      Sets the designated parameter to the given Reader, which will have the specified number of bytes.
      Specified by:
      setCharacterStream in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the java Reader which contains the UNICODE value
      length - the number of bytes in the stream
      Throws:
      SQLException - thrown on failure.
    • setClob

      public final void setClob(int parameterIndex, Reader reader) throws SQLException
      Sets the designated parameter to a Reader object. This method differs from the setCharacterStream(int,Reader) method because it informs the driver that the parameter value should be sent to the server as a CLOB.
      Specified by:
      setClob in interface PreparedStatement
      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

      PreparedStatement getPreparedStatement() throws SQLException
      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

      public final Statement getStatement() throws SQLException
      Override the BrokeredStatement's getStatement() to always return a PreparedStatement.
      Overrides:
      getStatement in class BrokeredStatement
      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

      public final long getVersionCounter() throws SQLException
      Description copied from interface: EnginePreparedStatement
      Get 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:
      getVersionCounter in interface EnginePreparedStatement
      Returns:
      version counter
      Throws:
      SQLException