Class ServerPreparedStatement

java.lang.Object
All Implemented Interfaces:
JdbcPreparedStatement, JdbcStatement, Query, java.lang.AutoCloseable, java.sql.PreparedStatement, java.sql.Statement, java.sql.Wrapper

public class ServerPreparedStatement
extends ClientPreparedStatement
JDBC Interface for MySQL-4.1 and newer server-side PreparedStatements.
  • Field Details

  • Constructor Details

    • ServerPreparedStatement

      protected ServerPreparedStatement​(JdbcConnection conn, java.lang.String sql, java.lang.String db, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
      Creates a new ServerPreparedStatement object.
      Parameters:
      conn - the connection creating us.
      sql - the SQL containing the statement to prepare.
      db - the database in use when we were created.
      resultSetType - ResultSet type
      resultSetConcurrency - ResultSet concurrency
      Throws:
      java.sql.SQLException - If an error occurs
  • Method Details

    • getInstance

      protected static ServerPreparedStatement getInstance​(JdbcConnection conn, java.lang.String sql, java.lang.String db, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
      Creates a prepared statement instance
      Parameters:
      conn - the connection creating us.
      sql - the SQL containing the statement to prepare.
      db - the database in use when we were created.
      resultSetType - ResultSet type
      resultSetConcurrency - ResultSet concurrency
      Returns:
      new ServerPreparedStatement
      Throws:
      java.sql.SQLException - If an error occurs
    • initQuery

      protected void initQuery()
      Overrides:
      initQuery in class ClientPreparedStatement
    • toString

      public java.lang.String toString()
      Description copied from class: ClientPreparedStatement
      Returns this PreparedStatement represented as a string.
      Overrides:
      toString in class ClientPreparedStatement
      Returns:
      this PreparedStatement represented as a string.
    • addBatch

      public void addBatch() throws java.sql.SQLException
      Specified by:
      addBatch in interface java.sql.PreparedStatement
      Overrides:
      addBatch in class ClientPreparedStatement
      Throws:
      java.sql.SQLException
    • asSql

      public java.lang.String asSql​(boolean quoteStreamsAndUnknowns) throws java.sql.SQLException
      Overrides:
      asSql in class ClientPreparedStatement
      Throws:
      java.sql.SQLException
    • checkClosed

      protected JdbcConnection checkClosed()
      Description copied from class: StatementImpl
      Checks if closed() has been called, and throws an exception if so
      Overrides:
      checkClosed in class StatementImpl
      Returns:
      connection
    • clearParameters

      public void clearParameters()
      Specified by:
      clearParameters in interface java.sql.PreparedStatement
      Overrides:
      clearParameters in class ClientPreparedStatement
    • setClosed

      protected void setClosed​(boolean flag)
    • close

      public void close() throws java.sql.SQLException
      Description copied from class: StatementImpl
      In many cases, it is desirable to immediately release a Statement'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 java.lang.AutoCloseable
      Specified by:
      close in interface java.sql.Statement
      Overrides:
      close in class StatementImpl
      Throws:
      java.sql.SQLException - if a database access error occurs
    • executeBatchSerially

      protected long[] executeBatchSerially​(int batchTimeout) throws java.sql.SQLException
      Description copied from class: ClientPreparedStatement
      Executes the current batch of statements by executing them one-by-one.
      Overrides:
      executeBatchSerially in class ClientPreparedStatement
      Parameters:
      batchTimeout - timeout for the batch execution
      Returns:
      a list of update counts
      Throws:
      java.sql.SQLException - if an error occurs
    • executeInternal

      protected <M extends Message> ResultSetInternalMethods executeInternal​(int maxRowsToRetrieve, M sendPacket, boolean createStreamingResultSet, boolean queryIsSelectOnly, ColumnDefinition metadata, boolean isBatch) throws java.sql.SQLException
      Description copied from class: ClientPreparedStatement
      Actually execute the prepared statement. This is here so server-side PreparedStatements can re-use most of the code from this class.
      Overrides:
      executeInternal in class ClientPreparedStatement
      Type Parameters:
      M - extends Message
      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?
      metadata - use this metadata instead of the one provided on wire
      isBatch - is this a batch query?
      Returns:
      the results as a ResultSet
      Throws:
      java.sql.SQLException - if an error occurs.
    • getBinding

      protected ServerPreparedQueryBindValue getBinding​(int parameterIndex, boolean forLongData) throws java.sql.SQLException
      Returns the structure representing the value that (can be)/(is) bound at the given parameter index.
      Parameters:
      parameterIndex - 1-based
      forLongData - is this for a stream?
      Returns:
      ServerPreparedQueryBindValue
      Throws:
      java.sql.SQLException - if a database access error occurs or this method is called on a closed PreparedStatement
    • getMetaData

      public java.sql.ResultSetMetaData getMetaData() throws java.sql.SQLException
      Specified by:
      getMetaData in interface java.sql.PreparedStatement
      Overrides:
      getMetaData in class ClientPreparedStatement
      Throws:
      java.sql.SQLException
    • getParameterMetaData

      public java.sql.ParameterMetaData getParameterMetaData() throws java.sql.SQLException
      Specified by:
      getParameterMetaData in interface java.sql.PreparedStatement
      Overrides:
      getParameterMetaData in class ClientPreparedStatement
      Throws:
      java.sql.SQLException
    • isNull

      public boolean isNull​(int paramIndex)
      Specified by:
      isNull in interface JdbcPreparedStatement
      Overrides:
      isNull in class ClientPreparedStatement
    • realClose

      public void realClose​(boolean calledExplicitly, boolean closeOpenResults) throws java.sql.SQLException
      Description copied from class: StatementImpl
      Closes this statement, and frees resources.
      Specified by:
      realClose in interface JdbcPreparedStatement
      Overrides:
      realClose in class ClientPreparedStatement
      Parameters:
      calledExplicitly - was this called from close()?
      closeOpenResults - should open result sets be closed?
      Throws:
      java.sql.SQLException - if an error occurs
    • rePrepare

      protected void rePrepare()
      Used by Connection when auto-reconnecting to retrieve 'lost' prepared statements.
      Throws:
      CJException - if an error occurs.
    • serverExecute

      protected ResultSetInternalMethods serverExecute​(int maxRowsToRetrieve, boolean createStreamingResultSet, ColumnDefinition metadata) throws java.sql.SQLException
      Tells the server to execute this prepared statement with the current parameter bindings.
          -   Server gets the command 'COM_EXECUTE' to execute the
              previously         prepared query. If there is any param markers;
        then client will send the data in the following format:
       
        [COM_EXECUTE:1]
        [STMT_ID:4]
        [NULL_BITS:(param_count+7)/8)]
        [TYPES_SUPPLIED_BY_CLIENT(0/1):1]
        [[length]data]
        [[length]data] .. [[length]data].
       
        (Note: Except for string/binary types; all other types will not be
        supplied with length field)
       
      Parameters:
      maxRowsToRetrieve - rows limit
      createStreamingResultSet - should c/J create a streaming result?
      metadata - use this metadata instead of the one provided on wire
      Returns:
      result set
      Throws:
      java.sql.SQLException - if a database access error occurs or this method is called on a closed PreparedStatement
    • serverPrepare

      protected void serverPrepare​(java.lang.String sql) throws java.sql.SQLException
      Throws:
      java.sql.SQLException
    • checkBounds

      protected void checkBounds​(int parameterIndex, int parameterIndexOffset) throws java.sql.SQLException
      Overrides:
      checkBounds in class ClientPreparedStatement
      Throws:
      java.sql.SQLException
    • setUnicodeStream

      @Deprecated public void setUnicodeStream​(int parameterIndex, java.io.InputStream x, int length) throws java.sql.SQLException
      Deprecated.
      Specified by:
      setUnicodeStream in interface java.sql.PreparedStatement
      Overrides:
      setUnicodeStream in class ClientPreparedStatement
      Throws:
      java.sql.SQLException
    • setURL

      public void setURL​(int parameterIndex, java.net.URL x) throws java.sql.SQLException
      Specified by:
      setURL in interface java.sql.PreparedStatement
      Overrides:
      setURL in class ClientPreparedStatement
      Throws:
      java.sql.SQLException
    • getServerStatementId

      public long getServerStatementId()
      Overrides:
      getServerStatementId in class StatementImpl
    • setOneBatchedParameterSet

      protected int setOneBatchedParameterSet​(java.sql.PreparedStatement batchedStatement, int batchedParamIndex, java.lang.Object paramSet) throws java.sql.SQLException
      Overrides:
      setOneBatchedParameterSet in class ClientPreparedStatement
      Throws:
      java.sql.SQLException
    • containsOnDuplicateKeyUpdateInSQL

      protected boolean containsOnDuplicateKeyUpdateInSQL()
      Overrides:
      containsOnDuplicateKeyUpdateInSQL in class ClientPreparedStatement
    • prepareBatchedInsertSQL

      protected ClientPreparedStatement prepareBatchedInsertSQL​(JdbcConnection localConn, int numBatches) throws java.sql.SQLException
      Description copied from class: ClientPreparedStatement
      Returns a prepared statement for the number of batched parameters, used when re-writing batch INSERTs.
      Overrides:
      prepareBatchedInsertSQL in class ClientPreparedStatement
      Parameters:
      localConn - the connection creating this statement
      numBatches - number of entries in a batch
      Returns:
      new ClientPreparedStatement
      Throws:
      java.sql.SQLException - if a database access error occurs or this method is called on a closed PreparedStatement
    • setPoolable

      public void setPoolable​(boolean poolable) throws java.sql.SQLException
      Specified by:
      setPoolable in interface java.sql.Statement
      Overrides:
      setPoolable in class StatementImpl
      Throws:
      java.sql.SQLException