Top Description Fields Constructors Methods
com.mysql.cj.jdbc

public Class StatementImpl

extends Object
implements JdbcStatement
Class Inheritance
All Implemented Interfaces
com.mysql.cj.jdbc.JdbcStatement, com.mysql.cj.Query, java.sql.Statement, java.lang.AutoCloseable, java.sql.Wrapper
Known Direct Subclasses
com.mysql.cj.jdbc.ClientPreparedStatement
Imports
java.io.IOException, .InputStream, java.math.BigInteger, java.sql.BatchUpdateException, .ResultSet, .SQLException, .SQLWarning, .Statement, java.util.ArrayList, .HashSet, .List, .Set, java.util.concurrent.atomic.AtomicBoolean, java.util.concurrent.locks.Lock, com.mysql.cj.CancelQueryTask, .Messages, .MysqlType, .NativeSession, .PingTarget, .Query, .QueryAttributesBindings, .QueryInfo, .QueryReturnType, .Session, .SimpleQuery, .TransactionEventHandler, com.mysql.cj.conf.HostInfo, .PropertyDefinitions, .PropertyKey, .RuntimeProperty, com.mysql.cj.exceptions.AssertionFailedException, .CJException, .CJOperationNotSupportedException, .CJTimeoutException, .ExceptionFactory, .ExceptionInterceptor, .MysqlErrorNumbers, .OperationCancelledException, .StatementIsClosedException, com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException, .MySQLTimeoutException, .SQLError, .SQLExceptionsMapping, com.mysql.cj.jdbc.result.CachedResultSetMetaData, .ResultSetFactory, .ResultSetImpl, .ResultSetInternalMethods, com.mysql.cj.log.ProfilerEvent, com.mysql.cj.protocol.Message, .ProtocolEntityFactory, .Resultset, .Resultset.Type, com.mysql.cj.protocol.a.NativeConstants, .NativeMessageBuilder, com.mysql.cj.protocol.a.result.ByteArrayRow, .ResultsetRowsStatic, com.mysql.cj.result.DefaultColumnDefinition, .Field, .Row, com.mysql.cj.telemetry.TelemetryAttribute, .TelemetryScope, .TelemetrySpan, .TelemetrySpanName, com.mysql.cj.util.StringUtils, .Util

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.

Field Summary

Modifier and TypeField and Description
protected ArrayList<Row>
protected String
charEncoding

The character encoding to use (if available)

private boolean
protected NativeMessageBuilder
protected volatile JdbcConnection
connection

The connection that created us

protected boolean
protected boolean
doEscapeProcessing

Should we process escape codes?

protected boolean
protected RuntimeProperty<Boolean>
protected RuntimeProperty<Boolean>
protected ExceptionInterceptor
protected ResultSetInternalMethods
protected boolean
holdResultsOpenOverClose

Should this statement hold results open over .close() regardless of connection's setting?

protected boolean
isClosed

Has this statement been closed?

private boolean
protected long
lastInsertId

The auto_increment value for the last insert

protected boolean
lastQueryIsOnDupKeyUpdate

Whether or not the last query was of the form ON DUPLICATE KEY UPDATE

protected boolean
protected RuntimeProperty<Integer>
protected int
maxFieldSize

The max field size for this statement

public int
maxRows

The maximum number of rows to return for this statement (-1 means _all_rows)

private Set<ResultSetInternalMethods>
openResultSets

Set of currently-open ResultSets

private int
private Resultset.Type
protected boolean
pedantic

Are we in pedantic mode?

protected static final String
protected PingTarget
protected boolean
profileSQL

Should we profile?

protected Query
protected ResultSetInternalMethods
results

The current results

protected int
resultSetConcurrency

The concurrency for this result set (updatable or not)

protected ResultSetFactory
protected boolean
protected RuntimeProperty<Boolean>
protected NativeSession
protected long
updateCount

The update count for this statement

public static final byte
public static final byte
public static final byte
protected boolean
useUsageAdvisor

Should we use the usage advisor?

protected SQLWarning
warningChain

The warnings chain.

Constructor Summary

AccessConstructor and Description
public
StatementImpl(JdbcConnection
the Connection instance that creates us
c
,
String
the database name in use when we were created
db
)

Constructor for a Statement.

Method Summary

Modifier and TypeMethod and Description
public void
addBatch(String
typically this is a SQL INSERT or UPDATE statement
sql
)

Implements java.sql.Statement.addBatch.

Adds the given SQL command to the current list of commands for this Statement object.

public void
public void
cancel()

Implements java.sql.Statement.cancel.

Cancels this Statement object if both the DBMS and driver support aborting an SQL statement.

private void
checkAndPerformCloseOnCompletionAction()

Check if all ResultSets generated by this statement are closed.

public void
protected JdbcConnection

Returns:

connection
checkClosed
()

Checks if closed() has been called, and throws an exception if so

protected void
checkNullOrEmptyQuery(String
the SQL to check
sql
)

Method checkNullOrEmptyQuery.

public void
public void
clearBatch()

Implements java.sql.Statement.clearBatch.

Empties this Statement object's current list of SQL commands.

public void
public void
clearWarnings()

Implements java.sql.Statement.clearWarnings.

Clears all the warnings reported on this Statement object.

public void
close()

Implements java.sql.Statement.close.

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.

protected void
closeAllOpenResults()

Close any open result sets that have been 'held open'

public void
closeOnCompletion()

Implements java.sql.Statement.closeOnCompletion.

Specifies that this Statement will be closed when all its dependent result sets are closed.

public void
protected boolean
private ResultSetInternalMethods

Returns:

result set
createResultSetUsingServerFetch
(String
query
sql
)

public void
disableStreamingResults()

Implements com.mysql.cj.jdbc.JdbcStatement.disableStreamingResults.

Resets this statements fetch size and result set type to the values they had before enableStreamingResults() was called.

public void
doClose(CloseOption...
options indicating how the close was initiated and/or what should be performed during the close
options
)

Implements com.mysql.cj.jdbc.JdbcStatement.doClose.

Close this Statement and release resources.

protected void
public void
enableStreamingResults()

Implements com.mysql.cj.jdbc.JdbcStatement.enableStreamingResults.

Workaround for containers that 'check' for sane values of Statement.setFetchSize() so that applications can use the Java variant of libmysql's mysql_use_result() behavior.

public boolean
execute(String
any SQL statement
sql
)

Implements java.sql.Statement.execute.

Executes the given SQL statement, which may return multiple results.

public boolean
execute(String
any SQL statement
sql
,
int
a constant indicating whether auto-generated keys should be made available for retrieval using the method getGeneratedKeys; one of the following constants: Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS
returnGeneratedKeys
)

Implements java.sql.Statement.execute.

Executes the given SQL statement, which may return multiple results, and signals the driver that any auto-generated keys should be made available for retrieval.

public boolean
execute(String
any SQL statement
sql
,
int[]
an array of the indexes of the columns in the inserted row that should be made available for retrieval by a call to the method getGeneratedKeys
generatedKeyIndices
)

Implements java.sql.Statement.execute.

Executes the given SQL statement, which may return multiple results, and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.

public boolean
execute(String
any SQL statement
sql
,
String[]
an array of the names of the columns in the inserted row that should be made available for retrieval by a call to the method getGeneratedKeys
generatedKeyNames
)

Implements java.sql.Statement.execute.

Executes the given SQL statement, which may return multiple results, and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.

public int[]
executeBatch()

Implements java.sql.Statement.executeBatch.

Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts.

protected long[]
private long[]

Returns:

update counts in the same manner as executeBatch()
executeBatchUsingMultiQueries
(boolean
is multi-queries syntax allowed?
multiQueriesEnabled
,
int
number of queries in a batch
nbrCommands
,
long
timeout for a single query in a batch
individualStatementTimeout
)

Rewrites batch into a single query to send to the server.

private boolean
executeInternal(String sql, boolean returnGeneratedKeys)

public long[]
executeLargeBatch()

Overrides default java.sql.Statement.executeLargeBatch.

Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts.

public long
executeLargeUpdate(String
an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
sql
)

Overrides default java.sql.Statement.executeLargeUpdate.

Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.

public long
executeLargeUpdate(String
an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
sql
,
int
a flag indicating whether auto-generated keys should be made available for retrieval; one of the following constants: Statement.RETURN_GENERATED_KEYS Statement.NO_GENERATED_KEYS
autoGeneratedKeys
)

Overrides default java.sql.Statement.executeLargeUpdate.

Executes the given SQL statement and signals the driver with the given flag about whether the auto-generated keys produced by this Statement object should be made available for retrieval.

public long
executeLargeUpdate(String
an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
sql
,
int[]
an array of column indexes indicating the columns that should be returned from the inserted row
columnIndexes
)

Overrides default java.sql.Statement.executeLargeUpdate.

Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.

public long
executeLargeUpdate(String
an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
sql
,
String[]
an array of the names of the columns that should be returned from the inserted row
columnNames
)

Overrides default java.sql.Statement.executeLargeUpdate.

Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.

public ResultSet
executeQuery(String
an SQL statement to be sent to the database, typically a static SQL SELECT statement
sql
)

Implements java.sql.Statement.executeQuery.

Executes the given SQL statement, which returns a single ResultSet object.

public void
public int
executeUpdate(String
an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
sql
)

Implements java.sql.Statement.executeUpdate.

Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.

public int
executeUpdate(String
an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
sql
,
int
a flag indicating whether auto-generated keys should be made available for retrieval; one of the following constants: Statement.RETURN_GENERATED_KEYS Statement.NO_GENERATED_KEYS
autoGeneratedKeys
)

Implements java.sql.Statement.executeUpdate.

Executes the given SQL statement and signals the driver with the given flag about whether the auto-generated keys produced by this Statement object should be made available for retrieval.

public int
executeUpdate(String
an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
sql
,
int[]
an array of column indexes indicating the columns that should be returned from the inserted row
columnIndexes
)

Implements java.sql.Statement.executeUpdate.

Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.

public int
executeUpdate(String
an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
sql
,
String[]
an array of the names of the columns that should be returned from the inserted row
columnNames
)

Implements java.sql.Statement.executeUpdate.

Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.

protected long
executeUpdateInternal(String sql, boolean isBatch, boolean returnGeneratedKeys)

protected ResultSetInternalMethods
public List<Object>
getBatchedArgs()

Implements com.mysql.cj.Query.getBatchedArgs.

Get the batched args as added by the addBatch method(s).

protected void
protected void
public Lock
public Connection
getConnection()

Implements java.sql.Statement.getConnection.

Retrieves the Connection object that produced this Statement object.

public String
public ExceptionInterceptor
public long
getExecuteTime()

Implements com.mysql.cj.Query.getExecuteTime.

Returns the elapsed time for the server to execute the query.

public int
getFetchDirection()

Implements java.sql.Statement.getFetchDirection.

Retrieves the direction for fetching rows from database tables that is the default for result sets generated from this Statement object.

public int
getFetchSize()

Implements java.sql.Statement.getFetchSize.

Retrieves the number of result set rows that is the default fetch size for ResultSet objects generated from this Statement object.

public ResultSet
getGeneratedKeys()

Implements java.sql.Statement.getGeneratedKeys.

Retrieves any auto-generated keys created as a result of executing this Statement object.

protected ResultSetInternalMethods
protected ResultSetInternalMethods
public int
getId()

Implements com.mysql.cj.Query.getId.

Returns the query id used when profiling

public long
getLargeMaxRows()

Overrides default java.sql.Statement.getLargeMaxRows.

Retrieves the maximum number of rows that a ResultSet object produced by this Statement object can contain.

public long
getLargeUpdateCount()

Overrides default java.sql.Statement.getLargeUpdateCount.

Retrieves the current result as an update count; if the result is a ResultSet object or there are no more results, -1 is returned.

public long

Returns:

the last update ID.
getLastInsertID
()

getLastInsertID returns the value of the auto_incremented key after an executeQuery() or excute() call.

public InputStream
getLocalInfileInputStream()

Implements com.mysql.cj.jdbc.JdbcStatement.getLocalInfileInputStream.

Returns the InputStream instance that will be used to send data in response to a "LOAD DATA LOCAL INFILE" statement.

public long

Returns:

the current update count.
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.

public int
getMaxFieldSize()

Implements java.sql.Statement.getMaxFieldSize.

Retrieves the maximum number of bytes that can be returned for character and binary column values in a ResultSet object produced by this Statement object.

public int
getMaxRows()

Implements java.sql.Statement.getMaxRows.

Retrieves the maximum number of rows that a ResultSet object produced by this Statement object can contain.

public boolean
getMoreResults()

Implements java.sql.Statement.getMoreResults.

Moves to this Statement object's next result, returns true if it is a ResultSet object, and implicitly closes any current ResultSet object(s) obtained with the method getResultSet.

public boolean
getMoreResults(int
one of the following Statement constants indicating what should happen to current ResultSet objects obtained using the method getResultSet: Statement.CLOSE_CURRENT_RESULT, Statement.KEEP_CURRENT_RESULT, or Statement.CLOSE_ALL_RESULTS
current
)

Implements java.sql.Statement.getMoreResults.

Moves to this Statement object's next result, deals with any current ResultSet object(s) according to the instructions specified by the given flag, and returns true if the next result is a ResultSet object.

public int
getOpenResultSetCount()

Implements com.mysql.cj.jdbc.JdbcStatement.getOpenResultSetCount.

Returns the number of open result sets for this statement.

public Query
public QueryAttributesBindings
public int
getQueryTimeout()

Implements java.sql.Statement.getQueryTimeout.

Retrieves the number of seconds the driver will wait for a Statement object to execute.

private long

Returns:

records count
getRecordCountFromInfo
(String
server info message
serverInfo
)

Parses actual record count from 'info' message

public int
public ResultSet
getResultSet()

Implements java.sql.Statement.getResultSet.

Retrieves the current result as a ResultSet object.

public int
getResultSetConcurrency()

Implements java.sql.Statement.getResultSetConcurrency.

Retrieves the result set concurrency for ResultSet objects generated by this Statement object.

public <T extends Resultset, M extends Message> ProtocolEntityFactory<T, M>
public int
getResultSetHoldability()

Implements java.sql.Statement.getResultSetHoldability.

Retrieves the result set holdability for ResultSet objects generated by this Statement object.

public ResultSetInternalMethods
public int
getResultSetType()

Implements java.sql.Statement.getResultSetType.

Retrieves the result set type for ResultSet objects generated by this Statement object.

public Resultset.Type
public long
public Session
public AtomicBoolean
public long
public int
getUpdateCount()

Implements java.sql.Statement.getUpdateCount.

Retrieves the current result as an update count; if the result is a ResultSet object or there are no more results, -1 is returned.

public SQLWarning
getWarnings()

Implements java.sql.Statement.getWarnings.

Retrieves the first warning reported by calls on this Statement object.

protected SQLException
handleExceptionForBatch(int endOfBatchIndex, int numValuesPerBatch, long[] updateCounts, SQLException ex)

protected final boolean
protected void
implicitlyCloseAllOpenResults()

Close all result sets in this statement.

protected void
public boolean
public boolean
isClosed()

Implements java.sql.Statement.isClosed.

Retrieves whether this Statement object has been closed.

public boolean
isCloseOnCompletion()

Implements java.sql.Statement.isCloseOnCompletion.

Returns a value indicating whether this Statement will be closed when all its dependent result sets are closed.

protected boolean

Returns:

true if the query does not produce a result set, false otherwise.
isNonResultSetProducingQuery
(String
the SQL to check
sql
)

Checks if the given SQL query does not return a result set.

public boolean
isPoolable()

Implements java.sql.Statement.isPoolable.

Returns a value indicating whether the Statement is poolable or not.

protected boolean

Returns:

true if the query produces a result set, false otherwise.
isResultSetProducingQuery
(String
the SQL to check
sql
)

Checks if the given SQL query is a result set producing query.

public boolean
isWrapperFor(Class<?>
a Class defining an interface.
iface
)

Implements java.sql.Wrapper.isWrapperFor.

Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does.

protected boolean

Returns:

true if this result set should be streamed row at-a-time, rather than read all at once.
meetsConditionsForStreamingResultSet
()

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
notifyResultSetClose(ResultSetInternalMethods
The ResultSet being closed
rs
)

Implements com.mysql.cj.jdbc.JdbcStatement.notifyResultSetClose.

Callback for ResultSet instances to notify the owning Statement when they are being closed.

protected int
processMultiCountsAndKeys(StatementImpl batchedStatement, int updateCountCounter, long[] updateCounts)

public void
public void
public void
public void
setClearWarningsCalled(boolean clearWarningsCalled)

Implements com.mysql.cj.Query.setClearWarningsCalled.

public void
public void
setCursorName(String
the new cursor name, which must be unique within a connection
name
)

Implements java.sql.Statement.setCursorName.

Sets the SQL cursor name to the given String, which will be used by subsequent Statement object execute methods.

public void
setEscapeProcessing(boolean
true to enable escape processing; false to disable it
enable
)

Implements java.sql.Statement.setEscapeProcessing.

Sets escape processing on or off.

public void
public void
setFetchDirection(int
the initial direction for processing rows
direction
)

Implements java.sql.Statement.setFetchDirection.

Gives the driver a hint as to the direction in which rows will be processed in ResultSet objects created using this Statement object.

public void
setFetchSize(int
the number of rows to fetch
rows
)

Implements java.sql.Statement.setFetchSize.

Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed for ResultSet objects generated by this Statement.

public void
public void
setLargeMaxRows(long
the new max rows limit; zero means there is no limit
max
)

Overrides default java.sql.Statement.setLargeMaxRows.

Sets the limit for the maximum number of rows that any ResultSet object generated by this Statement object can contain to the given number.

public void
setLocalInfileInputStream(InputStream
input stream
stream
)

Implements com.mysql.cj.jdbc.JdbcStatement.setLocalInfileInputStream.

Sets an InputStream instance that will be used to send data to the MySQL server for a "LOAD DATA LOCAL INFILE" statement rather than a FileInputStream or URLInputStream that represents the path given as an argument to the statement.

public void
setMaxFieldSize(int
the new column size limit in bytes; zero means there is no limit
max
)

Implements java.sql.Statement.setMaxFieldSize.

Sets the limit for the maximum number of bytes that can be returned for character and binary column values in a ResultSet object produced by this Statement object.

public void
setMaxRows(int
the new max rows limit; zero means there is no limit
max
)

Implements java.sql.Statement.setMaxRows.

Sets the limit for the maximum number of rows that any ResultSet object generated by this Statement object can contain to the given number.

public void
public void
setPoolable(boolean
requests that the statement be pooled if true and that the statement not be pooled if false
poolable
)

Implements java.sql.Statement.setPoolable.

Requests that a Statement be pooled or not pooled.

public void
setQueryTimeout(int
the new query timeout limit in seconds; zero means there is no limit
seconds
)

Implements java.sql.Statement.setQueryTimeout.

Sets the number of seconds the driver will wait for a Statement object to execute to the given number of seconds.

public void
pack-priv void
setResultSetConcurrency(int
concurrency flag
concurrencyFlag
)

Sets the concurrency for result sets generated by this statement

pack-priv void
setResultSetType(Resultset.Type typeFlag)

Sets the result set type for result sets generated by this statement

pack-priv void
setResultSetType(int typeFlag)

public void
public void
protected void
setupStreamingTimeout(JdbcConnection
created this statement
con
)

Adjust net_write_timeout to a higher value if we're streaming result sets.

public CancelQueryTask
startQueryTimer(Query stmtToCancel, long timeout)

Implements com.mysql.cj.Query.startQueryTimer.

public void
public void
stopQueryTimer(CancelQueryTask timeoutTask, boolean rethrowCancelReason, boolean checkCancelTimeout)

Implements com.mysql.cj.Query.stopQueryTimer.

public <T> T
unwrap(Class<T>
A Class defining an interface that the result must implement.
iface
)

Implements java.sql.Wrapper.unwrap.

Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy.

private boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait