Class PreparedStatement

java.lang.Object
com.mysql.jdbc.StatementImpl
com.mysql.jdbc.PreparedStatement
All Implemented Interfaces:
Statement, Wrapper, AutoCloseable, PreparedStatement, Statement, Wrapper
Direct Known Subclasses:
CallableStatement, JDBC4PreparedStatement, ServerPreparedStatement

public class PreparedStatement extends StatementImpl implements PreparedStatement
A SQL Statement is pre-compiled and stored in a PreparedStatement object. This object can then be used to efficiently execute this statement multiple times.

Note: The setXXX methods for setting IN parameter values must specify types that are compatible with the defined SQL type of the input parameter. For instance, if the IN parameter has SQL type Integer, then setInt should be used.

If arbitrary parameter type conversions are required, then the setObject method should be used with a target SQL type.

  • Field Details

    • batchHasPlainStatements

      protected boolean batchHasPlainStatements
      Does the batch (if any) contain "plain" statements added by Statement.addBatch(String)? If so, we can't re-write it to use multi-value or multi-queries.
    • firstCharOfStmt

      protected char firstCharOfStmt
      What is the first character of the prepared statement (used to check for SELECT vs. INSERT/UPDATE/DELETE)
    • isLoadDataQuery

      protected boolean isLoadDataQuery
      Is this query a LOAD DATA query?
    • isNull

      protected boolean[] isNull
    • numberOfExecutions

      protected int numberOfExecutions
    • originalSql

      protected String originalSql
      The SQL that was passed in to 'prepare'
    • parameterCount

      protected int parameterCount
      The number of parameters in this PreparedStatement
    • parameterMetaData

      protected MysqlParameterMetadata parameterMetaData
    • parameterTypes

      protected int[] parameterTypes
      Only used by statement interceptors at the moment to provide introspection of bound values
    • parseInfo

      protected PreparedStatement.ParseInfo parseInfo
    • useTrueBoolean

      protected boolean useTrueBoolean
      Are we using a version of MySQL where we can use 'true' boolean values?
    • usingAnsiMode

      protected boolean usingAnsiMode
    • batchedValuesClause

      protected String batchedValuesClause
    • batchCommandIndex

      protected int batchCommandIndex
      Command index of currently executing batch command.
    • serverSupportsFracSecs

      protected boolean serverSupportsFracSecs
    • rewrittenBatchSize

      protected int rewrittenBatchSize
  • Constructor Details

    • PreparedStatement

      public PreparedStatement(MySQLConnection conn, String catalog) throws SQLException
      Constructor used by server-side prepared statements
      Parameters:
      conn - the connection that created us
      catalog - the catalog in use when we were created
      Throws:
      SQLException - if an error occurs
    • PreparedStatement

      public PreparedStatement(MySQLConnection conn, String sql, String catalog) throws SQLException
      Constructor for the PreparedStatement class.
      Parameters:
      conn - the connection creating this statement
      sql - the SQL for this statement
      catalog - the catalog/database this statement should be issued against
      Throws:
      SQLException - if a database error occurs.
    • PreparedStatement

      public PreparedStatement(MySQLConnection conn, String sql, String catalog, PreparedStatement.ParseInfo cachedParseInfo) throws SQLException
      Creates a new PreparedStatement object.
      Parameters:
      conn - the connection creating this statement
      sql - the SQL for this statement
      catalog - the catalog/database this statement should be issued against
      cachedParseInfo - already created parseInfo.
      Throws:
      SQLException
  • Method Details

    • readFully

      protected static int readFully(Reader reader, char[] buf, int length) throws IOException
      Reads length bytes from reader into buf. Blocks until enough input is available
      Parameters:
      reader -
      buf -
      length -
      Throws:
      IOException
    • getInstance

      protected static PreparedStatement getInstance(MySQLConnection conn, String catalog) throws SQLException
      Creates a prepared statement instance -- We need to provide factory-style methods so we can support both JDBC3 (and older) and JDBC4 runtimes, otherwise the class verifier complains when it tries to load JDBC4-only interface classes that are present in JDBC4 method signatures.
      Throws:
      SQLException
    • getInstance

      protected static PreparedStatement getInstance(MySQLConnection conn, String sql, String catalog) throws SQLException
      Creates a prepared statement instance -- We need to provide factory-style methods so we can support both JDBC3 (and older) and JDBC4 runtimes, otherwise the class verifier complains when it tries to load JDBC4-only interface classes that are present in JDBC4 method signatures.
      Throws:
      SQLException
    • getInstance

      protected static PreparedStatement getInstance(MySQLConnection conn, String sql, String catalog, PreparedStatement.ParseInfo cachedParseInfo) throws SQLException
      Creates a prepared statement instance -- We need to provide factory-style methods so we can support both JDBC3 (and older) and JDBC4 runtimes, otherwise the class verifier complains when it tries to load JDBC4-only interface classes that are present in JDBC4 method signatures.
      Throws:
      SQLException
    • detectFractionalSecondsSupport

      protected void detectFractionalSecondsSupport() throws SQLException
      Throws:
      SQLException
    • addBatch

      public 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.
      See Also:
    • addBatch

      public void addBatch(String sql) throws SQLException
      Specified by:
      addBatch in interface Statement
      Overrides:
      addBatch in class StatementImpl
      Parameters:
      sql -
      Throws:
      SQLException
    • asSql

      public String asSql() throws SQLException
      Throws:
      SQLException
    • asSql

      public String asSql(boolean quoteStreamsAndUnknowns) throws SQLException
      Throws:
      SQLException
    • clearBatch

      public void clearBatch() throws SQLException
      Description copied from class: StatementImpl
      JDBC 2.0 Make the set of commands in the current batch empty. This method is optional.
      Specified by:
      clearBatch in interface Statement
      Overrides:
      clearBatch in class StatementImpl
      Throws:
      SQLException - if a database-access error occurs, or the driver does not support batch statements
    • clearParameters

      public void clearParameters() throws SQLException
      In general, parameter values remain in force for repeated used 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 - if a database access error occurs
    • checkReadOnlySafeStatement

      protected boolean checkReadOnlySafeStatement() throws SQLException
      Check to see if the statement is safe for read-only slaves after failover.
      Returns:
      true if safe for read-only.
      Throws:
      SQLException
    • execute

      public boolean execute() throws SQLException
      Some prepared statements return multiple results; the execute method handles these complex statements as well as the simpler form of statements handled by executeQuery and executeUpdate
      Specified by:
      execute in interface PreparedStatement
      Returns:
      true if the next result is a ResultSet; false if it is an update count or there are no more results
      Throws:
      SQLException - if a database access error occurs
    • executeBatchInternal

      protected long[] executeBatchInternal() throws SQLException
      Overrides:
      executeBatchInternal in class StatementImpl
      Throws:
      SQLException
    • canRewriteAsMultiValueInsertAtSqlLevel

      public boolean canRewriteAsMultiValueInsertAtSqlLevel() throws SQLException
      Throws:
      SQLException
    • getLocationOfOnDuplicateKeyUpdate

      protected int getLocationOfOnDuplicateKeyUpdate() throws SQLException
      Throws:
      SQLException
    • executePreparedBatchAsMultiStatement

      protected long[] executePreparedBatchAsMultiStatement(int batchTimeout) throws SQLException
      Rewrites the already prepared statement into a multi-statement query of 'statementsPerBatch' values and executes the entire batch using this new statement.
      Returns:
      update counts in the same fashion as executeBatch()
      Throws:
      SQLException
    • executeBatchedInserts

      protected long[] executeBatchedInserts(int batchTimeout) throws SQLException
      Rewrites the already prepared statement into a multi-value insert statement of 'statementsPerBatch' values and executes the entire batch using this new statement.
      Returns:
      update counts in the same fashion as executeBatch()
      Throws:
      SQLException
    • getValuesClause

      protected String getValuesClause() throws SQLException
      Throws:
      SQLException
    • computeBatchSize

      protected int computeBatchSize(int numBatchedArgs) throws SQLException
      Computes the optimum number of batched parameter lists to send without overflowing max_allowed_packet.
      Parameters:
      numBatchedArgs -
      Throws:
      SQLException
    • computeMaxParameterSetSizeAndBatchSize

      protected long[] computeMaxParameterSetSizeAndBatchSize(int numBatchedArgs) throws SQLException
      Computes the maximum parameter set size, and entire batch size given the number of arguments in the batch.
      Throws:
      SQLException
    • executeBatchSerially

      protected long[] executeBatchSerially(int batchTimeout) throws SQLException
      Executes the current batch of statements by executing them one-by-one.
      Returns:
      a list of update counts
      Throws:
      SQLException - if an error occurs
    • getDateTime

      public String getDateTime(String pattern)
    • executeInternal

      protected ResultSetInternalMethods executeInternal(int maxRowsToRetrieve, Buffer sendPacket, boolean createStreamingResultSet, boolean queryIsSelectOnly, Field[] metadataFromCache, boolean isBatch) throws SQLException
      Actually execute the prepared statement. This is here so server-side PreparedStatements can re-use most of the code from this class.
      Parameters:
      maxRowsToRetrieve - the max number of rows to return
      sendPacket - the packet to send
      createStreamingResultSet - should a 'streaming' result set be created?
      queryIsSelectOnly - is this query doing a SELECT?
      unpackFields -
      Returns:
      the results as a ResultSet
      Throws:
      SQLException - if an error occurs.
    • executeQuery

      public 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 - if a database access error occurs
    • executeUpdate

      public 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 - if a database access error occurs
    • executeUpdateInternal

      protected long executeUpdateInternal(boolean clearBatchedGeneratedKeysAndWarnings, boolean isBatch) throws SQLException
      Throws:
      SQLException
    • executeUpdateInternal

      protected long executeUpdateInternal(byte[][] batchedParameterStrings, InputStream[] batchedParameterStreams, boolean[] batchedIsStream, int[] batchedStreamLengths, boolean[] batchedIsNull, boolean isReallyBatch) throws SQLException
      Added to allow batch-updates
      Parameters:
      batchedParameterStrings - string values used in single statement
      batchedParameterStreams - stream values used in single statement
      batchedIsStream - flags for streams used in single statement
      batchedStreamLengths - lengths of streams to be read.
      batchedIsNull - flags for parameters that are null
      Returns:
      the update count
      Throws:
      SQLException - if a database error occurs
    • containsOnDuplicateKeyUpdateInSQL

      protected boolean containsOnDuplicateKeyUpdateInSQL()
    • fillSendPacket

      protected Buffer fillSendPacket() throws SQLException
      Creates the packet that contains the query to be sent to the server.
      Returns:
      A Buffer filled with the query representing the PreparedStatement.
      Throws:
      SQLException - if an error occurs.
    • fillSendPacket

      protected Buffer fillSendPacket(byte[][] batchedParameterStrings, InputStream[] batchedParameterStreams, boolean[] batchedIsStream, int[] batchedStreamLengths) throws SQLException
      Creates the packet that contains the query to be sent to the server.
      Parameters:
      batchedParameterStrings - the parameters as strings
      batchedParameterStreams - the parameters as streams
      batchedIsStream - is the given parameter a stream?
      batchedStreamLengths - the lengths of the streams (if appropriate)
      Returns:
      a Buffer filled with the query that represents this statement
      Throws:
      SQLException - if an error occurs.
    • prepareBatchedInsertSQL

      protected PreparedStatement prepareBatchedInsertSQL(MySQLConnection localConn, int numBatches) throws SQLException
      Returns a prepared statement for the number of batched parameters, used when re-writing batch INSERTs.
      Throws:
      SQLException
    • setRetrieveGeneratedKeys

      protected void setRetrieveGeneratedKeys(boolean flag) throws SQLException
      Throws:
      SQLException
    • getRewrittenBatchSize

      public int getRewrittenBatchSize()
    • getNonRewrittenSql

      public String getNonRewrittenSql() throws SQLException
      Throws:
      SQLException
    • getBytesRepresentation

      public byte[] getBytesRepresentation(int parameterIndex) throws SQLException
      Parameters:
      parameterIndex -
      Throws:
      SQLException
    • getBytesRepresentationForBatch

      protected byte[] getBytesRepresentationForBatch(int parameterIndex, int commandIndex) throws SQLException
      Get bytes representation for a parameter in a statement batch.
      Parameters:
      parameterIndex -
      commandIndex -
      Throws:
      SQLException
    • getMetaData

      public ResultSetMetaData getMetaData() throws SQLException
      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 - if a database-access error occurs.
    • isSelectQuery

      protected boolean isSelectQuery() throws SQLException
      Throws:
      SQLException
    • getParameterMetaData

      public ParameterMetaData getParameterMetaData() throws SQLException
      Specified by:
      getParameterMetaData in interface PreparedStatement
      Throws:
      SQLException
      See Also:
    • getParseInfo

    • isNull

      boolean isNull(int paramIndex) throws SQLException
      Throws:
      SQLException
    • realClose

      protected void realClose(boolean calledExplicitly, boolean closeOpenResults) throws SQLException
      Closes this statement, releasing all resources
      Overrides:
      realClose in class StatementImpl
      Parameters:
      calledExplicitly - was this called by close()?
      Throws:
      SQLException - if an error occurs
    • setArray

      public void setArray(int i, Array x) throws SQLException
      JDBC 2.0 Set an Array parameter.
      Specified by:
      setArray in interface PreparedStatement
      Parameters:
      i - the first parameter is 1, the second is 2, ...
      x - an object representing an SQL array
      Throws:
      SQLException - because this method is not implemented.
      NotImplemented
    • setAsciiStream

      public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException
      When a very large ASCII value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.InputStream. JDBC will read the data from the stream as needed, until it reaches end-of-file. The JDBC driver will do any necessary conversion from ASCII to the database char format.

      Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.

      Specified by:
      setAsciiStream in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1...
      x - the parameter value
      length - the number of bytes in the stream
      Throws:
      SQLException - if a database access error occurs
    • setBigDecimal

      public 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...
      x - the parameter value
      Throws:
      SQLException - if a database access error occurs
    • setBinaryStream

      public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException
      When a very large binary value is input to a LONGVARBINARY parameter, it may be more practical to send it via a java.io.InputStream. JDBC will read the data from the stream as needed, until it reaches end-of-file.

      Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.

      Specified by:
      setBinaryStream in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1...
      x - the parameter value
      length - the number of bytes to read from the stream (ignored)
      Throws:
      SQLException - if a database access error occurs
    • setBlob

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

      public void setBlob(int i, Blob x) throws SQLException
      JDBC 2.0 Set a BLOB parameter.
      Specified by:
      setBlob in interface PreparedStatement
      Parameters:
      i - the first parameter is 1, the second is 2, ...
      x - an object representing a BLOB
      Throws:
      SQLException - if a database error occurs
    • setBoolean

      public void setBoolean(int parameterIndex, boolean x) throws SQLException
      Set a parameter to a Java boolean value. The driver converts this to a SQL BIT value when it sends it to the database.
      Specified by:
      setBoolean in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1...
      x - the parameter value
      Throws:
      SQLException - if a database access error occurs
    • setByte

      public 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...
      x - the parameter value
      Throws:
      SQLException - if a database access error occurs
    • setBytes

      public 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...
      x - the parameter value
      Throws:
      SQLException - if a database access error occurs
    • setBytes

      protected void setBytes(int parameterIndex, byte[] x, boolean checkForIntroducer, boolean escapeForMBChars) throws SQLException
      Throws:
      SQLException
    • setBytesNoEscape

      protected void setBytesNoEscape(int parameterIndex, byte[] parameterAsBytes) throws SQLException
      Used by updatable result sets for refreshRow() because the parameter has already been escaped for updater or inserter prepared statements.
      Parameters:
      parameterIndex - the parameter to set.
      parameterAsBytes - the parameter as a string.
      Throws:
      SQLException - if an error occurs
    • setBytesNoEscapeNoQuotes

      protected void setBytesNoEscapeNoQuotes(int parameterIndex, byte[] parameterAsBytes) throws SQLException
      Throws:
      SQLException
    • setCharacterStream

      public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException
      JDBC 2.0 When a very large UNICODE value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.Reader. JDBC will read the data from the stream as needed, until it reaches end-of-file. The JDBC driver will do any necessary conversion from UNICODE to the database char format.

      Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.

      Specified by:
      setCharacterStream in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      reader - the java reader which contains the UNICODE data
      length - the number of characters in the stream
      Throws:
      SQLException - if a database-access error occurs.
    • setClob

      public void setClob(int i, Clob x) throws SQLException
      JDBC 2.0 Set a CLOB parameter.
      Specified by:
      setClob in interface PreparedStatement
      Parameters:
      i - the first parameter is 1, the second is 2, ...
      x - an object representing a CLOB
      Throws:
      SQLException - if a database error occurs
    • setDate

      public 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...
      x - the parameter value
      Throws:
      SQLException - if a database access error occurs
    • setDate

      public void setDate(int parameterIndex, Date x, Calendar cal) 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
      cal - the calendar to interpret the date with
      Throws:
      SQLException - if a database-access error occurs.
    • setDouble

      public 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...
      x - the parameter value
      Throws:
      SQLException - if a database access error occurs
    • setFloat

      public 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...
      x - the parameter value
      Throws:
      SQLException - if a database access error occurs
    • setInt

      public 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...
      x - the parameter value
      Throws:
      SQLException - if a database access error occurs
    • setInternal

      protected final void setInternal(int paramIndex, byte[] val) throws SQLException
      Throws:
      SQLException
    • checkBounds

      protected void checkBounds(int paramIndex, int parameterIndexOffset) throws SQLException
      Throws:
      SQLException
    • setInternal

      protected final void setInternal(int paramIndex, String val) throws SQLException
      Throws:
      SQLException
    • setLong

      public 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...
      x - the parameter value
      Throws:
      SQLException - if a database access error occurs
    • setNull

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

      Note: You must specify the parameters SQL type (although MySQL ignores it)

      Specified by:
      setNull in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, etc...
      sqlType - the SQL type code defined in java.sql.Types
      Throws:
      SQLException - if a database access error occurs
    • setNull

      public void setNull(int parameterIndex, int sqlType, String arg) 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
      arg - argument parameters for null
      Throws:
      SQLException - if a database-access error occurs.
    • setObject

      public void setObject(int parameterIndex, Object parameterObj) throws SQLException
      Specified by:
      setObject in interface PreparedStatement
      Throws:
      SQLException
    • setObject

      public void setObject(int parameterIndex, Object parameterObj, int targetSqlType) throws SQLException
      Specified by:
      setObject in interface PreparedStatement
      Parameters:
      parameterIndex -
      parameterObj -
      targetSqlType -
      Throws:
      SQLException
    • setObject

      public void setObject(int parameterIndex, Object parameterObj, int targetSqlType, int scale) throws SQLException
      Set the value of a parameter using an object; use the java.lang equivalent objects for integral values.

      The given Java object will be converted to the targetSqlType before being sent to the database.

      note that this method may be used to pass database-specific abstract data types. This is done by using a Driver-specific Java type and using a targetSqlType of java.sql.Types.OTHER

      Specified by:
      setObject in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1...
      parameterObj - the object containing the input parameter value
      targetSqlType - The SQL type to be send to the database
      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 - if a database access error occurs
    • setOneBatchedParameterSet

      protected int setOneBatchedParameterSet(PreparedStatement batchedStatement, int batchedParamIndex, Object paramSet) throws SQLException
      Throws:
      SQLException
    • setRef

      public void setRef(int i, Ref x) throws SQLException
      JDBC 2.0 Set a REF(<structured-type>) parameter.
      Specified by:
      setRef in interface PreparedStatement
      Parameters:
      i - the first parameter is 1, the second is 2, ...
      x - an object representing data of an SQL REF Type
      Throws:
      SQLException - if a database error occurs
      NotImplemented
    • setShort

      public 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...
      x - the parameter value
      Throws:
      SQLException - if a database access error occurs
    • setString

      public 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...
      x - the parameter value
      Throws:
      SQLException - if a database access error occurs
    • setTime

      public void setTime(int parameterIndex, Time x, Calendar cal) 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
      cal - the cal specifying the timezone
      Throws:
      SQLException - if a database-access error occurs.
    • setTime

      public 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...));
      x - the parameter value
      Throws:
      SQLException - if a database access error occurs
    • setTimestamp

      public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) 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
      cal - the calendar specifying the timezone to use
      Throws:
      SQLException - if a database-access error occurs.
    • setTimestamp

      public 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...
      x - the parameter value
      Throws:
      SQLException - if a database access error occurs
    • setTimestampInternal

      protected void setTimestampInternal(int parameterIndex, Timestamp x, Calendar targetCalendar, TimeZone tz, boolean rollForward, int fractionalLength, boolean useSSPSCompatibleTimezoneShift) 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.
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      x - the parameter value
      tz - the timezone to use
      Throws:
      SQLException - if a database-access error occurs.
    • setUnicodeStream

      @Deprecated public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException
      Deprecated.
      When a very large Unicode value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.InputStream. JDBC will read the data from the stream as needed, until it reaches end-of-file. The JDBC driver will do any necessary conversion from UNICODE to the database char format.

      Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.

      Specified by:
      setUnicodeStream in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1...
      x - the parameter value
      length - the number of bytes to read from the stream
      Throws:
      SQLException - if a database access error occurs
    • setURL

      public void setURL(int parameterIndex, URL arg) throws SQLException
      Specified by:
      setURL in interface PreparedStatement
      Throws:
      SQLException
      See Also:
    • toString

      public String toString()
      Returns this PreparedStatement represented as a string.
      Overrides:
      toString in class Object
      Returns:
      this PreparedStatement represented as a string.
    • getParameterIndexOffset

      protected int getParameterIndexOffset()
      For calling stored functions, this will be -1 as we don't really count the first '?' parameter marker, it's only syntax, but JDBC counts it as #1, otherwise it will return 0
    • setAsciiStream

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

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

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

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

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

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

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

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

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

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

      public void setNString(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 with introducer _utf8 (depending on the arguments size relative to the driver's limits on VARCHARs) when it sends it to the database. If charset is set as utf8, this method just call setString.
      Specified by:
      setNString in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1...
      x - the parameter value
      Throws:
      SQLException - if a database access error occurs
    • setNCharacterStream

      public void setNCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException
      JDBC 2.0 When a very large UNICODE value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.Reader. JDBC will read the data from the stream as needed, until it reaches end-of-file. The JDBC driver will do any necessary conversion from UNICODE to the database char format.

      Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.

      Specified by:
      setNCharacterStream in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      reader - the java reader which contains the UNICODE data
      length - the number of characters in the stream
      Throws:
      SQLException - if a database-access error occurs.
    • setNClob

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

      public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException
      JDBC 4.0 Set a NCLOB parameter.
      Specified by:
      setNClob in interface PreparedStatement
      Parameters:
      parameterIndex - the first parameter is 1, the second is 2, ...
      reader - the java reader which contains the UNICODE data
      length - the number of characters in the stream
      Throws:
      SQLException - if a database error occurs
    • getParameterBindings

      public ParameterBindings getParameterBindings() throws SQLException
      Throws:
      SQLException
    • getPreparedSql

      public String getPreparedSql()
    • getUpdateCount

      public int getUpdateCount() throws SQLException
      Description copied from class: StatementImpl
      getUpdateCount returns the current result as an update count, if the result is a ResultSet or there are no more results, -1 is returned. It should only be called once per result.
      Specified by:
      getUpdateCount in interface Statement
      Overrides:
      getUpdateCount in class StatementImpl
      Returns:
      the current result as an update count.
      Throws:
      SQLException - if a database access error occurs
    • canRewrite

      protected static boolean canRewrite(String sql, boolean isOnDuplicateKeyUpdate, int locationOfOnDuplicateKeyUpdate, int statementStartPos)
    • executeLargeUpdate

      public long executeLargeUpdate() throws SQLException
      JDBC 4.2 Same as PreparedStatement.executeUpdate() but returns long instead of int.
      Specified by:
      executeLargeUpdate in interface PreparedStatement
      Throws:
      SQLException