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

public Class ServerPreparedStatement

extends ClientPreparedStatement
Class Inheritance
Imports
java.io.IOException, .InputStream, java.net.URL, java.sql.ParameterMetaData, .SQLException, .Wrapper, java.util.ArrayList, java.util.concurrent.locks.Lock, com.mysql.cj.BindValue, .CancelQueryTask, .Messages, .NativeSession, .PreparedQuery, .QueryBindings, .QueryInfo, .ServerPreparedQuery, .Session, com.mysql.cj.conf.PropertyKey, com.mysql.cj.exceptions.CJException, .ExceptionFactory, .ExceptionInterceptor, .MysqlErrorNumbers, .WrongArgumentException, com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException, .MySQLTimeoutException, .SQLError, .SQLExceptionsMapping, com.mysql.cj.jdbc.result.ResultSetInternalMethods, .ResultSetMetaData, com.mysql.cj.protocol.ColumnDefinition, .Message, com.mysql.cj.telemetry.TelemetryAttribute, .TelemetryScope, .TelemetrySpan, .TelemetrySpanName

JDBC Interface for MySQL-4.1 and newer server-side PreparedStatements.

Field Summary

Modifier and TypeField and Description
private boolean
private boolean
invalid

Has this prepared statement been marked invalid?

private CJException
invalidationException

If this statement has been marked invalid, what was the reason?

protected boolean
protected boolean
Inherited from com.mysql.cj.jdbc.ClientPreparedStatement:
batchedValuesClausebatchHasPlainStatementsparameterMetaDatarewrittenBatchSize

Constructor Summary

AccessConstructor and Description
protected
ServerPreparedStatement(JdbcConnection
the connection creating us.
conn
,
String
the SQL containing the statement to prepare.
sql
,
String
the database in use when we were created.
db
,
int
ResultSet type
resultSetType
,
int
ResultSet concurrency
resultSetConcurrency
)

Creates a new ServerPreparedStatement object.

Method Summary

Modifier and TypeMethod and Description
public void
addBatch()

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.addBatch.

Implements java.sql.PreparedStatement.addBatch.

Adds a set of parameters to this PreparedStatement object's batch of commands.

private static SQLException
protected void
checkBounds(int parameterIndex, int parameterIndexOffset)

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.checkBounds.

protected JdbcConnection
checkClosed()

Overrides com.mysql.cj.jdbc.StatementImpl.checkClosed.

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

public void
clearParameters()

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.clearParameters.

Implements java.sql.PreparedStatement.clearParameters.

Clears the current parameter values immediately.

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

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.doClose.

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

Close this Statement and release resources.

protected long[]
executeBatchSerially(long
timeout for the batch execution
batchTimeout
)

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.executeBatchSerially.

Executes the current batch of statements by executing them one-by-one.

protected <M extends Message> ResultSetInternalMethods
executeInternal(int
the max number of rows to return
maxRowsToRetrieve
,
M
the packet to send
sendPacket
,
boolean
should a 'streaming' result set be created?
createStreamingResultSet
,
boolean
is this query doing a SELECT?
queryIsSelectOnly
,
ColumnDefinition
use this metadata instead of the one provided on wire
metadata
,
boolean
is this a batch query?
isBatch
)

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal.

Actually execute the prepared statement.

protected BindValue

Returns:

BindValue
getBinding
(int
1-based
parameterIndex
,
boolean
is this for a stream?
forLongData
)

Returns the structure representing the value that (can be)/(is) bound at the given parameter index.

protected static ServerPreparedStatement

Returns:

new ServerPreparedStatement
getInstance
(JdbcConnection
the connection creating us.
conn
,
String
the SQL containing the statement to prepare.
sql
,
String
the database in use when we were created.
db
,
int
ResultSet type
resultSetType
,
int
ResultSet concurrency
resultSetConcurrency
)

Creates a prepared statement instance

public ResultSetMetaData
getMetaData()

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.getMetaData.

Implements java.sql.PreparedStatement.getMetaData.

Retrieves a ResultSetMetaData object that contains information about the columns of the ResultSet object that will be returned when this PreparedStatement object is executed.

public ParameterMetaData
getParameterMetaData()

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.getParameterMetaData.

Implements java.sql.PreparedStatement.getParameterMetaData.

Retrieves the number, types and properties of this PreparedStatement object's parameters.

public long
protected void
public boolean
protected ClientPreparedStatement
prepareBatchedInsertSQL(JdbcConnection
the connection creating this statement
localConn
,
int
number of entries in a batch
numBatches
)

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.prepareBatchedInsertSQL.

Returns a prepared statement for the number of batched parameters, used when re-writing batch INSERTs.

protected void
rePrepare()

Used by Connection when auto-reconnecting to retrieve 'lost' prepared statements.

protected ResultSetInternalMethods

Returns:

result set
serverExecute
(int
rows limit
maxRowsToRetrieve
,
boolean
should c/J create a streaming result?
createStreamingResultSet
,
ColumnDefinition
use this metadata instead of the one provided on wire
metadata
)

Tells the server to execute this prepared statement with the current parameter bindings.

protected void
protected void
setClosed(boolean flag)

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

Overrides com.mysql.cj.jdbc.StatementImpl.setPoolable.

Implements java.sql.Statement.setPoolable.

Requests that a Statement be pooled or not pooled.

public void
setUnicodeStream(int
the first parameter is 1, the second is 2, ...
parameterIndex
,
InputStream
a java.io.InputStream object that contains the Unicode parameter value
x
,
int
the number of bytes in the stream
length
)

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.setUnicodeStream.

Implements java.sql.PreparedStatement.setUnicodeStream.

Deprecated

Sets the designated parameter to the given input stream, which will have the specified number of bytes.

public void
setURL(int
the first parameter is 1, the second is 2, ...
parameterIndex
,
URL
the java.net.URL object to be set
x
)

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.setURL.

Implements java.sql.PreparedStatement.setURL.

Sets the designated parameter to the given java.net.URL value.

public String
toString()

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.toString.

Returns this PreparedStatement represented as a string.

Inherited from com.mysql.cj.jdbc.ClientPreparedStatement:
addBatchcheckReadOnlySafeStatementclearBatchexecuteexecuteBatchInternalexecuteBatchWithMultiValuesClauseexecuteLargeUpdateexecutePreparedBatchAsMultiStatementexecuteQueryexecuteUpdateexecuteUpdateInternalexecuteUpdateInternalgetBytesRepresentationgetCoreParameterIndexgetInstancegetInstancegetParameterBindingsgetParameterIndexOffsetgetPreparedSqlgetQueryBindingsgetQueryInfogetUpdateCountisResultSetProducingQuerysetArraysetAsciiStreamsetAsciiStreamsetAsciiStreamsetBigDecimalsetBigIntegersetBinaryStreamsetBinaryStreamsetBinaryStreamsetBlobsetBlobsetBlobsetBooleansetBytesetBytessetBytessetCharacterStreamsetCharacterStreamsetCharacterStreamsetClobsetClobsetClobsetDatesetDatesetDoublesetFloatsetIntsetLongsetNCharacterStreamsetNCharacterStreamsetNClobsetNClobsetNClobsetNStringsetNullsetNullsetNullsetObjectsetObjectsetObjectsetObjectsetObjectsetOneBatchedParameterSetsetRefsetRetrieveGeneratedKeyssetRowIdsetShortsetSQLXMLsetStringsetTimesetTimesetTimestampsetTimestamp

Field Detail

hasOnDuplicateKeyUpdateback to summary
private boolean hasOnDuplicateKeyUpdate
invalidback to summary
private boolean invalid

Has this prepared statement been marked invalid?

invalidationExceptionback to summary
private CJException invalidationException

If this statement has been marked invalid, what was the reason?

isCacheableback to summary
protected boolean isCacheable
isCachedback to summary
protected boolean isCached

Constructor Detail

ServerPreparedStatementback to summary
protected ServerPreparedStatement(JdbcConnection conn, String sql, String db, int resultSetType, int resultSetConcurrency) throws SQLException

Creates a new ServerPreparedStatement object.

Parameters
conn:JdbcConnection

the connection creating us.

sql:String

the SQL containing the statement to prepare.

db:String

the database in use when we were created.

resultSetType:int

ResultSet type

resultSetConcurrency:int

ResultSet concurrency

Exceptions
SQLException:
If an error occurs

Method Detail

addBatchback to summary
public void addBatch() throws SQLException

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.addBatch.

Implements java.sql.PreparedStatement.addBatch.

Doc from java.sql.PreparedStatement.addBatch.

Adds a set of parameters to this PreparedStatement object's batch of commands.

Annotations
@Override
Exceptions
SQLException:
if a database access error occurs or this method is called on a closed PreparedStatement
appendMessageToExceptionback to summary
private static SQLException appendMessageToException(SQLException sqlEx, String messageToAppend, ExceptionInterceptor interceptor)
checkBoundsback to summary
protected void checkBounds(int parameterIndex, int parameterIndexOffset) throws SQLException

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.checkBounds.

Annotations
@Override
checkClosedback to summary
protected JdbcConnection checkClosed()

Overrides com.mysql.cj.jdbc.StatementImpl.checkClosed.

Doc from com.mysql.cj.jdbc.StatementImpl.checkClosed.

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

Returns:JdbcConnection

connection

Annotations
@Override
clearParametersback to summary
public void clearParameters()

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.clearParameters.

Implements java.sql.PreparedStatement.clearParameters.

Doc from java.sql.PreparedStatement.clearParameters.

Clears the current parameter values immediately.

In general, parameter values remain in force for repeated use of a statement. Setting a parameter value automatically clears its previous value. However, in some cases it is useful to immediately release the resources used by the current parameter values; this can be done by calling the method clearParameters.

Annotations
@Override
containsOnDuplicateKeyUpdateback to summary
protected boolean containsOnDuplicateKeyUpdate()

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.containsOnDuplicateKeyUpdate.

Annotations
@Override
doCloseback to summary
public void doClose(CloseOption... options) throws SQLException

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.doClose.

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

Close this Statement and release resources. By default the close is considered explicit, does not propagate to dependents and allows caching the Statement.

Parameters
options:CloseOption[]

Doc from com.mysql.cj.jdbc.JdbcStatement.doClose.

options indicating how the close was initiated and/or what should be performed during the close

Annotations
@Override
Exceptions
SQLException:

Doc from com.mysql.cj.jdbc.JdbcStatement.doClose.

if an error occurs

executeBatchSeriallyback to summary
protected long[] executeBatchSerially(long batchTimeout) throws SQLException

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.executeBatchSerially.

Doc from com.mysql.cj.jdbc.ClientPreparedStatement.executeBatchSerially.

Executes the current batch of statements by executing them one-by-one.

Parameters
batchTimeout:long

timeout for the batch execution

Returns:long[]

a list of update counts

Annotations
@Override
Exceptions
SQLException:
if an error occurs
executeInternalback to summary
protected <M extends Message> ResultSetInternalMethods executeInternal(int maxRowsToRetrieve, M sendPacket, boolean createStreamingResultSet, boolean queryIsSelectOnly, ColumnDefinition metadata, boolean isBatch) throws SQLException

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal.

Doc from com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal.

Actually execute the prepared statement. This is here so server-side PreparedStatements can re-use most of the code from this class.

Parameters
<M>
extends Message
maxRowsToRetrieve:int

the max number of rows to return

sendPacket:M

the packet to send

createStreamingResultSet:boolean

should a 'streaming' result set be created?

queryIsSelectOnly:boolean

is this query doing a SELECT?

metadata:ColumnDefinition

use this metadata instead of the one provided on wire

isBatch:boolean

is this a batch query?

Returns:ResultSetInternalMethods

the results as a ResultSet

Annotations
@Override
Exceptions
SQLException:
if an error occurs.
getBindingback to summary
protected BindValue getBinding(int parameterIndex, boolean forLongData) throws SQLException

Returns the structure representing the value that (can be)/(is) bound at the given parameter index.

Parameters
parameterIndex:int

1-based

forLongData:boolean

is this for a stream?

Returns:BindValue

BindValue

Exceptions
SQLException:
if a database access error occurs or this method is called on a closed PreparedStatement
getInstanceback to summary
protected static ServerPreparedStatement getInstance(JdbcConnection conn, String sql, String db, int resultSetType, int resultSetConcurrency) throws SQLException

Creates a prepared statement instance

Parameters
conn:JdbcConnection

the connection creating us.

sql:String

the SQL containing the statement to prepare.

db:String

the database in use when we were created.

resultSetType:int

ResultSet type

resultSetConcurrency:int

ResultSet concurrency

Returns:ServerPreparedStatement

new ServerPreparedStatement

Exceptions
SQLException:
If an error occurs
getMetaDataback to summary
public ResultSetMetaData getMetaData() throws SQLException

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.getMetaData.

Implements java.sql.PreparedStatement.getMetaData.

Doc from java.sql.PreparedStatement.getMetaData.

Retrieves a ResultSetMetaData object that contains information about the columns of the ResultSet object that will be returned when this PreparedStatement object is executed.

Because a PreparedStatement object is precompiled, it is possible to know about the ResultSet object that it will return without having to execute it. Consequently, it is possible to invoke the method getMetaData on a PreparedStatement object rather than waiting to execute it and then invoking the ResultSet.getMetaData method on the ResultSet object that is returned.

Note

Using this method may be expensive for some drivers due to the lack of underlying DBMS support.

Returns:ResultSetMetaData

the description of a ResultSet object's columns or null if the driver cannot return a ResultSetMetaData object

Annotations
@Override
Exceptions
SQLException:
if a database access error occurs or this method is called on a closed PreparedStatement
getParameterMetaDataback to summary
public ParameterMetaData getParameterMetaData() throws SQLException

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.getParameterMetaData.

Implements java.sql.PreparedStatement.getParameterMetaData.

Doc from java.sql.PreparedStatement.getParameterMetaData.

Retrieves the number, types and properties of this PreparedStatement object's parameters.

Returns:ParameterMetaData

a ParameterMetaData object that contains information about the number, types and properties for each parameter marker of this PreparedStatement object

Annotations
@Override
Exceptions
SQLException:
if a database access error occurs or this method is called on a closed PreparedStatement
getServerStatementIdback to summary
public long getServerStatementId()

Overrides com.mysql.cj.jdbc.StatementImpl.getServerStatementId.

Annotations
@Override
initQueryback to summary
protected void initQuery()

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.initQuery.

Annotations
@Override
isNullback to summary
public boolean isNull(int paramIndex)

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.isNull.

Implements com.mysql.cj.jdbc.JdbcPreparedStatement.isNull.

Annotations
@Override
prepareBatchedInsertSQLback to summary
protected ClientPreparedStatement prepareBatchedInsertSQL(JdbcConnection localConn, int numBatches) throws SQLException

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.prepareBatchedInsertSQL.

Doc from com.mysql.cj.jdbc.ClientPreparedStatement.prepareBatchedInsertSQL.

Returns a prepared statement for the number of batched parameters, used when re-writing batch INSERTs.

Parameters
localConn:JdbcConnection

the connection creating this statement

numBatches:int

number of entries in a batch

Returns:ClientPreparedStatement

new ClientPreparedStatement

Annotations
@Override
Exceptions
SQLException:
if a database access error occurs or this method is called on a closed PreparedStatement
rePrepareback to summary
protected void rePrepare()

Used by Connection when auto-reconnecting to retrieve 'lost' prepared statements.

Exceptions
CJException:
if an error occurs.
serverExecuteback to summary
protected ResultSetInternalMethods serverExecute(int maxRowsToRetrieve, boolean createStreamingResultSet, ColumnDefinition metadata) throws 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:int

rows limit

createStreamingResultSet:boolean

should c/J create a streaming result?

metadata:ColumnDefinition

use this metadata instead of the one provided on wire

Returns:ResultSetInternalMethods

result set

Exceptions
SQLException:
if a database access error occurs or this method is called on a closed PreparedStatement
serverPrepareback to summary
protected void serverPrepare(String sql) throws SQLException
setClosedback to summary
protected void setClosed(boolean flag)
setPoolableback to summary
public void setPoolable(boolean poolable) throws SQLException

Overrides com.mysql.cj.jdbc.StatementImpl.setPoolable.

Implements java.sql.Statement.setPoolable.

Doc from java.sql.Statement.setPoolable.

Requests that a Statement be pooled or not pooled. The value specified is a hint to the statement pool implementation indicating whether the application wants the statement to be pooled. It is up to the statement pool manager as to whether the hint is used.

The poolable value of a statement is applicable to both internal statement caches implemented by the driver and external statement caches implemented by application servers and other applications.

By default, a Statement is not poolable when created, and a PreparedStatement and CallableStatement are poolable when created.

Parameters
poolable:boolean

requests that the statement be pooled if true and that the statement not be pooled if false

Annotations
@Override
Exceptions
SQLException:
if this method is called on a closed Statement
setUnicodeStreamback to summary
public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.setUnicodeStream.

Implements java.sql.PreparedStatement.setUnicodeStream.

Doc from java.sql.PreparedStatement.setUnicodeStream.

Deprecated

Sets the designated parameter to the given input stream, which will have the specified number of bytes. 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 object. The data will be read from the stream as needed until end-of-file is reached. The JDBC driver will do any necessary conversion from Unicode to the database char format. The byte format of the Unicode stream must be a Java UTF-8, as defined in the Java Virtual Machine Specification.

Note

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

Parameters
parameterIndex:int

the first parameter is 1, the second is 2, ...

x:InputStream

a java.io.InputStream object that contains the Unicode parameter value

length:int

the number of bytes in the stream

Annotations
@Deprecated
@Override
Exceptions
SQLException:
if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement
setURLback to summary
public void setURL(int parameterIndex, URL x) throws SQLException

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.setURL.

Implements java.sql.PreparedStatement.setURL.

Doc from java.sql.PreparedStatement.setURL.

Sets the designated parameter to the given java.net.URL value. The driver converts this to an SQL DATALINK value when it sends it to the database.

Parameters
parameterIndex:int

the first parameter is 1, the second is 2, ...

x:URL

the java.net.URL object to be set

Annotations
@Override
Exceptions
SQLException:
if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement
toStringback to summary
public String toString()

Overrides com.mysql.cj.jdbc.ClientPreparedStatement.toString.

Doc from com.mysql.cj.jdbc.ClientPreparedStatement.toString.

Returns this PreparedStatement represented as a string.

Returns:String

this PreparedStatement represented as a string.

Annotations
@Override