Home » MySQL-JDBC-5.1.11 » com.mysql.jdbc » [javadoc | source]
com.mysql.jdbc
public class: StatementImpl [javadoc | source]
java.lang.Object
   com.mysql.jdbc.StatementImpl

All Implemented Interfaces:
    Statement

Direct Known Subclasses:
    CallableStatement, JDBC4PreparedStatement, JDBC4CallableStatement, PreparedStatement, JDBC4ServerPreparedStatement, ServerPreparedStatement

A Statement object is used for executing a static SQL statement and obtaining the results produced by it.

Only one ResultSet per Statement can be open at any point in time. Therefore, if the reading of one ResultSet is interleaved with the reading of another, each must have been generated by different Statements. All statement execute methods implicitly close a statement's current ResultSet if an open one exists.

Nested Class Summary:
class  StatementImpl.CancelTask  Thread used to implement query timeouts...Eventually we could be more efficient and have one thread with timers, but this is a straightforward and simple way to implement a feature that isn't used all that often. 
Field Summary
protected static final  String PING_MARKER     
protected  Object cancelTimeoutMutex    Mutex to prevent race between returning query results and noticing that we're timed-out or cancelled. 
protected static  int statementCounter    Used to generate IDs when profiling. 
public static final  byte USES_VARIABLES_FALSE     
public static final  byte USES_VARIABLES_TRUE     
public static final  byte USES_VARIABLES_UNKNOWN     
protected  boolean wasCancelled     
protected  boolean wasCancelledByTimeout     
protected  List batchedArgs    Holds batched commands 
protected  SingleByteCharsetConverter charConverter    The character converter to use (if available) 
protected  String charEncoding    The character encoding to use (if available) 
protected  ConnectionImpl connection    The connection that created us 
protected  long connectionId     
protected  String currentCatalog    The catalog in use 
protected  boolean doEscapeProcessing    Should we process escape codes? 
protected  ProfilerEventHandler eventSink    If we're profiling, where should events go to? 
protected  boolean isClosed    Has this statement been closed? 
protected  long lastInsertId    The auto_increment value for the last insert 
protected  int maxFieldSize    The max field size for this statement 
protected  int maxRows    The maximum number of rows to return for this statement (-1 means _all_ rows) 
protected  boolean maxRowsChanged    Has someone changed this for this statement? 
protected  Set openResults    Set of currently-open ResultSets 
protected  boolean pedantic    Are we in pedantic mode? 
protected  Throwable pointOfOrigin    Where this statement was created, only used if profileSql or useUsageAdvisor set to true. 
protected  boolean profileSQL    Should we profile? 
protected  ResultSetInternalMethods results    The current results 
protected  int resultSetConcurrency    The concurrency for this result set (updatable or not) 
protected  int resultSetType    The type of this result set (scroll sensitive or in-sensitive) 
protected  int statementId    Used to identify this statement when profiling. 
protected  int timeoutInMillis    The timeout for a query 
protected  long updateCount    The update count for this statement 
protected  boolean useUsageAdvisor    Should we use the usage advisor? 
protected  SQLWarning warningChain    The warnings chain. 
protected  boolean holdResultsOpenOverClose    Should this statement hold results open over .close() irregardless of connection's setting? 
protected  ArrayList batchedGeneratedKeys     
protected  boolean retrieveGeneratedKeys     
protected  boolean continueBatchOnError     
protected  PingTarget pingTarget     
protected  boolean useLegacyDatetimeCode     
protected  boolean lastQueryIsOnDupKeyUpdate    Whether or not the last query was of the form ON DUPLICATE KEY UPDATE 
Constructor:
 public StatementImpl(ConnectionImpl c,
    String catalog) throws SQLException 
    Constructor for a Statement.
    Parameters:
    c - the Connection instantation that creates us
    catalog - the database name in use when we were created
    Throws:
    SQLException - if an error occurs.
Method from com.mysql.jdbc.StatementImpl Summary:
addBatch,   cancel,   checkClosed,   checkForDml,   checkNullOrEmptyQuery,   clearBatch,   clearWarnings,   close,   closeAllOpenResults,   containsOnDuplicateKeyInString,   createStreamingResultSet,   disableStreamingResults,   doPingInstead,   enableStreamingResults,   execute,   execute,   execute,   execute,   executeBatch,   executeQuery,   executeSimpleNonQuery,   executeUpdate,   executeUpdate,   executeUpdate,   executeUpdate,   executeUpdate,   findStartOfStatement,   generatePingResultSet,   getBatchedGeneratedKeys,   getBatchedGeneratedKeys,   getCalendarInstanceForSessionOrNew,   getConnection,   getExceptionInterceptor,   getFetchDirection,   getFetchSize,   getGeneratedKeys,   getGeneratedKeysInternal,   getGeneratedKeysInternal,   getId,   getLastInsertID,   getLocalInfileInputStream,   getLongUpdateCount,   getMaxFieldSize,   getMaxRows,   getMoreResults,   getMoreResults,   getOnDuplicateKeyLocation,   getOpenResultSetCount,   getQueryTimeout,   getResultSet,   getResultSetConcurrency,   getResultSetHoldability,   getResultSetInternal,   getResultSetType,   getUpdateCount,   getWarnings,   handleExceptionForBatch,   hasDeadlockOrTimeoutRolledBackTx,   isClosed,   isPoolable,   isWrapperFor,   processMultiCountsAndKeys,   realClose,   removeOpenResultSet,   resetCancelledState,   setCursorName,   setEscapeProcessing,   setFetchDirection,   setFetchSize,   setHoldResultsOpenOverClose,   setLocalInfileInputStream,   setMaxFieldSize,   setMaxRows,   setPingTarget,   setPoolable,   setQueryTimeout,   setResultSetConcurrency,   setResultSetType,   unwrap
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from com.mysql.jdbc.StatementImpl Detail:
 public synchronized  void addBatch(String sql) throws SQLException 
    DOCUMENT ME!
 public  void cancel() throws SQLException 
    Cancels this Statement object if both the DBMS and driver support aborting an SQL statement. This method can be used by one thread to cancel a statement that is being executed by another thread.
 protected  void checkClosed() throws SQLException 
    Checks if closed() has been called, and throws an exception if so
 protected  void checkForDml(String sql,
    char firstStatementChar) throws SQLException 
    Checks if the given SQL query with the given first non-ws char is a DML statement. Throws an exception if it is.
 protected  void checkNullOrEmptyQuery(String sql) throws SQLException 
    Method checkNullOrEmptyQuery.
 public synchronized  void clearBatch() throws SQLException 
    JDBC 2.0 Make the set of commands in the current batch empty. This method is optional.
 public  void clearWarnings() throws SQLException 
    After this call, getWarnings returns null until a new warning is reported for this Statement.
 public synchronized  void close() throws SQLException 
    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.

 protected synchronized  void closeAllOpenResults() 
    Close any open result sets that have been 'held open'
 protected boolean containsOnDuplicateKeyInString(String sql) 
 protected boolean createStreamingResultSet() 
    We only stream result sets when they are forward-only, read-only, and the fetch size has been set to Integer.MIN_VALUE
 public  void disableStreamingResults() throws SQLException 
 protected  void doPingInstead() throws SQLException 
 public  void enableStreamingResults() throws SQLException 
 public boolean execute(String sql) throws SQLException 
    Execute a SQL statement that may return multiple results. We don't have to worry about this since we do not support multiple ResultSets. You can use getResultSet or getUpdateCount to retrieve the result.
 public boolean execute(String sql,
    int returnGeneratedKeys) throws SQLException 
 public boolean execute(String sql,
    int[] generatedKeyIndices) throws SQLException 
 public boolean execute(String sql,
    String[] generatedKeyNames) throws SQLException 
 public synchronized int[] executeBatch() throws SQLException 
    JDBC 2.0 Submit a batch of commands to the database for execution. This method is optional.
 public ResultSet executeQuery(String sql) throws SQLException 
    Execute a SQL statement that retruns a single ResultSet
 protected  void executeSimpleNonQuery(ConnectionImpl c,
    String nonQuery) throws SQLException 
 public int executeUpdate(String sql) 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 Any IDs generated for AUTO_INCREMENT fields can be retrieved by casting this Statement to org.gjt.mm.mysql.Statement and calling the getLastInsertID() method.
 public int executeUpdate(String sql,
    int returnGeneratedKeys) throws SQLException 
 public int executeUpdate(String sql,
    int[] generatedKeyIndices) throws SQLException 
 public int executeUpdate(String sql,
    String[] generatedKeyNames) throws SQLException 
 protected int executeUpdate(String sql,
    boolean isBatch,
    boolean returnGeneratedKeys) throws SQLException 
 protected int findStartOfStatement(String sql) 
 protected ResultSetInternalMethods generatePingResultSet() throws SQLException 
 protected  void getBatchedGeneratedKeys(Statement batchedStatement) throws SQLException 
 protected  void getBatchedGeneratedKeys(int maxKeys) throws SQLException 
 protected Calendar getCalendarInstanceForSessionOrNew() 
    Optimization to only use one calendar per-session, or calculate it for each call, depending on user configuration
 public Connection getConnection() throws SQLException 
    JDBC 2.0 Return the Connection that produced the Statement.
 public ExceptionInterceptor getExceptionInterceptor() 
 public int getFetchDirection() throws SQLException 
    JDBC 2.0 Determine the fetch direction.
 public int getFetchSize() throws SQLException 
    JDBC 2.0 Determine the default fetch size.
 public synchronized ResultSet getGeneratedKeys() throws SQLException 
    DOCUMENT ME!
 protected ResultSet getGeneratedKeysInternal() throws SQLException 
 protected synchronized ResultSet getGeneratedKeysInternal(int numKeys) throws SQLException 
 protected int getId() 
    Returns the id used when profiling
 public long getLastInsertID() 
    getLastInsertID returns the value of the auto_incremented key after an executeQuery() or excute() call.

    This gets around the un-threadsafe behavior of "select LAST_INSERT_ID()" which is tied to the Connection that created this Statement, and therefore could have had many INSERTS performed before one gets a chance to call "select LAST_INSERT_ID()".

 public synchronized InputStream getLocalInfileInputStream() 
 public long getLongUpdateCount() 
    getLongUpdateCount 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.

    This method returns longs as MySQL server versions newer than 3.22.4 return 64-bit values for update counts

 public int getMaxFieldSize() throws SQLException 
    The maxFieldSize limit (in bytes) is the maximum amount of data returned for any column value; it only applies to BINARY, VARBINARY, LONGVARBINARY, CHAR, VARCHAR and LONGVARCHAR columns. If the limit is exceeded, the excess data is silently discarded.
 public int getMaxRows() throws SQLException 
    The maxRows limit is set to limit the number of rows that any ResultSet can contain. If the limit is exceeded, the excess rows are silently dropped.
 public boolean getMoreResults() throws SQLException 
    getMoreResults moves to a Statement's next result. If it returns true, this result is a ResulSet.
 public synchronized boolean getMoreResults(int current) throws SQLException 
 protected int getOnDuplicateKeyLocation(String sql) 
 public synchronized int getOpenResultSetCount() 
 public int getQueryTimeout() throws SQLException 
    The queryTimeout limit is the number of seconds the driver will wait for a Statement to execute. If the limit is exceeded, a SQLException is thrown.
 public ResultSet getResultSet() throws SQLException 
    getResultSet returns the current result as a ResultSet. It should only be called once per result.
 public int getResultSetConcurrency() throws SQLException 
    JDBC 2.0 Determine the result set concurrency.
 public int getResultSetHoldability() throws SQLException 
 protected ResultSetInternalMethods getResultSetInternal() 
 public int getResultSetType() throws SQLException 
    JDBC 2.0 Determine the result set type.
 public int getUpdateCount() throws SQLException 
    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.
 public SQLWarning getWarnings() throws SQLException 
    The first warning reported by calls on this Statement is returned. A Statement's execute methods clear its java.sql.SQLWarning chain. Subsequent Statement warnings will be chained to this java.sql.SQLWarning.

    The Warning chain is automatically cleared each time a statement is (re)executed.

    Note: If you are processing a ResultSet then any warnings associated with ResultSet reads will be chained on the ResultSet object.

 protected SQLException handleExceptionForBatch(int endOfBatchIndex,
    int numValuesPerBatch,
    int[] updateCounts,
    SQLException ex) throws BatchUpdateException 
 protected final boolean hasDeadlockOrTimeoutRolledBackTx(SQLException ex) 
 public synchronized boolean isClosed() throws SQLException 
 public boolean isPoolable() throws SQLException 
 public boolean isWrapperFor(Class iface) throws SQLException 
    Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does. Returns false otherwise. If this implements the interface then return true, else if this is a wrapper then return the result of recursively calling isWrapperFor on the wrapped object. If this does not implement the interface and is not a wrapper, return false. This method should be implemented as a low-cost operation compared to unwrap so that callers can use this method to avoid expensive unwrap calls that may fail. If this method returns true then calling unwrap with the same argument should succeed.
 protected int processMultiCountsAndKeys(StatementImpl batchedStatement,
    int updateCountCounter,
    int[] updateCounts) throws SQLException 
 protected synchronized  void realClose(boolean calledExplicitly,
    boolean closeOpenResults) throws SQLException 
    Closes this statement, and frees resources.
 public synchronized  void removeOpenResultSet(ResultSet rs) 
 protected synchronized  void resetCancelledState() 
 public  void setCursorName(String name) throws SQLException 
    setCursorName defines the SQL cursor name that will be used by subsequent execute methods. This name can then be used in SQL positioned update/delete statements to identify the current row in the ResultSet generated by this statement. If a database doesn't support positioned update/delete, this method is a no-op.

    Note: This MySQL driver does not support cursors.

 public  void setEscapeProcessing(boolean enable) throws SQLException 
    If escape scanning is on (the default), the driver will do escape substitution before sending the SQL to the database.
 public  void setFetchDirection(int direction) throws SQLException 
    JDBC 2.0 Give a hint as to the direction in which the rows in a result set will be processed. The hint applies only to result sets created using this Statement object. The default value is ResultSet.FETCH_FORWARD.
 public  void setFetchSize(int rows) throws SQLException 
    JDBC 2.0 Give the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed. The number of rows specified only affects result sets created using this statement. If the value specified is zero, then the hint is ignored. The default value is zero.
 protected  void setHoldResultsOpenOverClose(boolean holdResultsOpenOverClose) 
 public synchronized  void setLocalInfileInputStream(InputStream stream) 
 public  void setMaxFieldSize(int max) throws SQLException 
    Sets the maxFieldSize
 public  void setMaxRows(int max) throws SQLException 
    Set the maximum number of rows
 public synchronized  void setPingTarget(PingTarget pingTarget) 
 public  void setPoolable(boolean poolable) throws SQLException 
 public  void setQueryTimeout(int seconds) throws SQLException 
    Sets the queryTimeout limit
  void setResultSetConcurrency(int concurrencyFlag) 
    Sets the concurrency for result sets generated by this statement
  void setResultSetType(int typeFlag) 
    Sets the result set type for result sets generated by this statement
 public Object unwrap(Class iface) throws SQLException 
    Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy. The result may be either the object found to implement the interface or a proxy for that object. If the receiver implements the interface then that is the object. If the receiver is a wrapper and the wrapped object implements the interface then that is the object. Otherwise the object is the result of calling unwrap recursively on the wrapped object. If the receiver is not a wrapper and does not implement the interface, then an SQLException is thrown.