Package com.mysql.cj.jdbc
Class ServerPreparedStatement
java.lang.Object
com.mysql.cj.jdbc.StatementImpl
com.mysql.cj.jdbc.ClientPreparedStatement
com.mysql.cj.jdbc.ServerPreparedStatement
- 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.
-
Nested Class Summary
-
Field Summary
Fields Modifier and Type Field Description protected boolean
isCacheable
protected boolean
isCached
Fields inherited from class com.mysql.cj.jdbc.ClientPreparedStatement
batchedValuesClause, batchHasPlainStatements, parameterMetaData, rewrittenBatchSize
Fields inherited from class com.mysql.cj.jdbc.StatementImpl
batchedGeneratedKeys, charEncoding, commandBuilder, connection, continueBatchOnError, doEscapeProcessing, dontCheckOnDuplicateKeyUpdateInSQL, dontTrackOpenResources, dumpQueriesOnException, exceptionInterceptor, generatedKeysResults, holdResultsOpenOverClose, isClosed, lastInsertId, lastQueryIsOnDupKeyUpdate, logSlowQueries, maxAllowedPacket, maxFieldSize, maxRows, openResults, pedantic, PING_MARKER, pingTarget, profileSQL, query, results, resultSetConcurrency, resultSetFactory, retrieveGeneratedKeys, rewriteBatchedStatements, session, updateCount, USES_VARIABLES_FALSE, USES_VARIABLES_TRUE, USES_VARIABLES_UNKNOWN, useUsageAdvisor, warningChain
-
Constructor Summary
Constructors Modifier Constructor Description protected
ServerPreparedStatement(JdbcConnection conn, java.lang.String sql, java.lang.String db, int resultSetType, int resultSetConcurrency)
Creates a new ServerPreparedStatement object. -
Method Summary
Modifier and Type Method Description void
addBatch()
java.lang.String
asSql(boolean quoteStreamsAndUnknowns)
protected void
checkBounds(int parameterIndex, int parameterIndexOffset)
protected JdbcConnection
checkClosed()
Checks if closed() has been called, and throws an exception if sovoid
clearParameters()
void
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 boolean
containsOnDuplicateKeyUpdateInSQL()
protected long[]
executeBatchSerially(int batchTimeout)
Executes the current batch of statements by executing them one-by-one.protected <M extends Message>
ResultSetInternalMethodsexecuteInternal(int maxRowsToRetrieve, M sendPacket, boolean createStreamingResultSet, boolean queryIsSelectOnly, ColumnDefinition metadata, boolean isBatch)
Actually execute the prepared statement.protected ServerPreparedQueryBindValue
getBinding(int parameterIndex, boolean forLongData)
Returns the structure representing the value that (can be)/(is) bound at the given parameter index.protected static ServerPreparedStatement
getInstance(JdbcConnection conn, java.lang.String sql, java.lang.String db, int resultSetType, int resultSetConcurrency)
Creates a prepared statement instancejava.sql.ResultSetMetaData
getMetaData()
java.sql.ParameterMetaData
getParameterMetaData()
long
getServerStatementId()
protected void
initQuery()
boolean
isNull(int paramIndex)
protected ClientPreparedStatement
prepareBatchedInsertSQL(JdbcConnection localConn, int numBatches)
Returns a prepared statement for the number of batched parameters, used when re-writing batch INSERTs.void
realClose(boolean calledExplicitly, boolean closeOpenResults)
Closes this statement, and frees resources.protected void
rePrepare()
Used by Connection when auto-reconnecting to retrieve 'lost' prepared statements.protected ResultSetInternalMethods
serverExecute(int maxRowsToRetrieve, boolean createStreamingResultSet, ColumnDefinition metadata)
Tells the server to execute this prepared statement with the current parameter bindings.protected void
serverPrepare(java.lang.String sql)
protected void
setClosed(boolean flag)
protected int
setOneBatchedParameterSet(java.sql.PreparedStatement batchedStatement, int batchedParamIndex, java.lang.Object paramSet)
void
setPoolable(boolean poolable)
void
setUnicodeStream(int parameterIndex, java.io.InputStream x, int length)
Deprecated.void
setURL(int parameterIndex, java.net.URL x)
java.lang.String
toString()
Returns this PreparedStatement represented as a string.Methods inherited from class com.mysql.cj.jdbc.ClientPreparedStatement
addBatch, asSql, checkReadOnlySafeStatement, clearBatch, execute, executeBatchedInserts, executeBatchInternal, executeLargeUpdate, executePreparedBatchAsMultiStatement, executeQuery, executeUpdate, executeUpdateInternal, executeUpdateInternal, getBytesRepresentation, getCoreParameterIndex, getInstance, getInstance, getOrigBytes, getParameterBindings, getParameterIndexOffset, getParseInfo, getPreparedSql, getQueryBindings, getUpdateCount, isSelectQuery, setArray, setAsciiStream, setAsciiStream, setAsciiStream, setBigDecimal, setBigInteger, setBinaryStream, setBinaryStream, setBinaryStream, setBlob, setBlob, setBlob, setBoolean, setByte, setBytes, setBytes, setBytesNoEscape, setBytesNoEscapeNoQuotes, setCharacterStream, setCharacterStream, setCharacterStream, setClob, setClob, setClob, setDate, setDate, setDouble, setFloat, setInt, setLong, setNCharacterStream, setNCharacterStream, setNClob, setNClob, setNClob, setNString, setNull, setNull, setNull, setObject, setObject, setObject, setObject, setObject, setRef, setRetrieveGeneratedKeys, setRowId, setShort, setSQLXML, setString, setTime, setTime, setTimestamp, setTimestamp, setTimestamp
Methods inherited from class com.mysql.cj.jdbc.StatementImpl
addBatch, cancel, checkCancelTimeout, checkForDml, checkNullOrEmptyQuery, clearBatchedArgs, clearWarnings, closeAllOpenResults, closeOnCompletion, closeQuery, containsOnDuplicateKeyInString, createStreamingResultSet, disableStreamingResults, doPingInstead, enableStreamingResults, execute, execute, execute, execute, executeBatch, executeLargeBatch, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeQuery, executeSimpleNonQuery, executeUpdate, executeUpdate, executeUpdate, executeUpdate, executeUpdateInternal, findStartOfStatement, generatePingResultSet, getBatchedArgs, getBatchedGeneratedKeys, getBatchedGeneratedKeys, getCancelTimeoutMutex, getConnection, getCurrentDatabase, getExceptionInterceptor, getExecuteTime, getFetchDirection, getFetchSize, getGeneratedKeys, getGeneratedKeysInternal, getGeneratedKeysInternal, getId, getLargeMaxRows, getLargeUpdateCount, getLastInsertID, getLocalInfileInputStream, getLongUpdateCount, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getOpenResultSetCount, getQuery, getQueryTimeout, getResultFetchSize, getResultSet, getResultSetConcurrency, getResultSetFactory, getResultSetHoldability, getResultSetInternal, getResultSetType, getResultType, getSession, getStatementExecuting, getTimeoutInMillis, getWarnings, handleExceptionForBatch, hasDeadlockOrTimeoutRolledBackTx, implicitlyCloseAllOpenResults, isClearWarningsCalled, isClosed, isCloseOnCompletion, isPoolable, isWrapperFor, processMultiCountsAndKeys, removeOpenResultSet, resetCancelledState, setCancelStatus, setClearWarningsCalled, setCurrentDatabase, setCursorName, setEscapeProcessing, setExecuteTime, setFetchDirection, setFetchSize, setHoldResultsOpenOverClose, setLargeMaxRows, setLocalInfileInputStream, setMaxFieldSize, setMaxRows, setPingTarget, setQueryTimeout, setResultFetchSize, setResultType, setTimeoutInMillis, setupStreamingTimeout, startQueryTimer, statementBegins, stopQueryTimer, unwrap
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.mysql.cj.jdbc.JdbcStatement
disableStreamingResults, enableStreamingResults, getExceptionInterceptor, getLocalInfileInputStream, getOpenResultSetCount, getQuery, removeOpenResultSet, setHoldResultsOpenOverClose, setLocalInfileInputStream, setPingTarget
Methods inherited from interface com.mysql.cj.Query
addBatch, checkCancelTimeout, clearBatchedArgs, closeQuery, getBatchedArgs, getCancelTimeoutMutex, getCurrentDatabase, getExecuteTime, getId, getResultFetchSize, getResultSetFactory, getResultType, getSession, getStatementExecuting, getTimeoutInMillis, isClearWarningsCalled, resetCancelledState, setCancelStatus, setClearWarningsCalled, setCurrentDatabase, setExecuteTime, setResultFetchSize, setResultType, setTimeoutInMillis, startQueryTimer, statementBegins, stopQueryTimer
Methods inherited from interface java.sql.Statement
cancel, clearWarnings, closeOnCompletion, enquoteIdentifier, enquoteLiteral, enquoteNCharLiteral, execute, execute, execute, execute, executeBatch, executeLargeBatch, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeQuery, executeUpdate, executeUpdate, executeUpdate, executeUpdate, getConnection, getFetchDirection, getFetchSize, getGeneratedKeys, getLargeMaxRows, getLargeUpdateCount, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getWarnings, isClosed, isCloseOnCompletion, isPoolable, isSimpleIdentifier, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setLargeMaxRows, setMaxFieldSize, setMaxRows, setQueryTimeout
-
Field Details
-
isCacheable
protected boolean isCacheable -
isCached
protected boolean isCached
-
-
Constructor Details
-
ServerPreparedStatement
protected ServerPreparedStatement(JdbcConnection conn, java.lang.String sql, java.lang.String db, int resultSetType, int resultSetConcurrency) throws java.sql.SQLExceptionCreates 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 typeresultSetConcurrency
- 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.SQLExceptionCreates 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 typeresultSetConcurrency
- ResultSet concurrency- Returns:
- new ServerPreparedStatement
- Throws:
java.sql.SQLException
- If an error occurs
-
initQuery
protected void initQuery()- Overrides:
initQuery
in classClientPreparedStatement
-
toString
public java.lang.String toString()Description copied from class:ClientPreparedStatement
Returns this PreparedStatement represented as a string.- Overrides:
toString
in classClientPreparedStatement
- Returns:
- this PreparedStatement represented as a string.
-
addBatch
public void addBatch() throws java.sql.SQLException- Specified by:
addBatch
in interfacejava.sql.PreparedStatement
- Overrides:
addBatch
in classClientPreparedStatement
- Throws:
java.sql.SQLException
-
asSql
public java.lang.String asSql(boolean quoteStreamsAndUnknowns) throws java.sql.SQLException- Overrides:
asSql
in classClientPreparedStatement
- Throws:
java.sql.SQLException
-
checkClosed
Description copied from class:StatementImpl
Checks if closed() has been called, and throws an exception if so- Overrides:
checkClosed
in classStatementImpl
- Returns:
- connection
-
clearParameters
public void clearParameters()- Specified by:
clearParameters
in interfacejava.sql.PreparedStatement
- Overrides:
clearParameters
in classClientPreparedStatement
-
setClosed
protected void setClosed(boolean flag) -
close
public void close() throws java.sql.SQLExceptionDescription 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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.sql.Statement
- Overrides:
close
in classStatementImpl
- Throws:
java.sql.SQLException
- if a database access error occurs
-
executeBatchSerially
protected long[] executeBatchSerially(int batchTimeout) throws java.sql.SQLExceptionDescription copied from class:ClientPreparedStatement
Executes the current batch of statements by executing them one-by-one.- Overrides:
executeBatchSerially
in classClientPreparedStatement
- 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.SQLExceptionDescription 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 classClientPreparedStatement
- Type Parameters:
M
- extendsMessage
- Parameters:
maxRowsToRetrieve
- the max number of rows to returnsendPacket
- the packet to sendcreateStreamingResultSet
- should a 'streaming' result set be created?queryIsSelectOnly
- is this query doing a SELECT?metadata
- use this metadata instead of the one provided on wireisBatch
- 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.SQLExceptionReturns the structure representing the value that (can be)/(is) bound at the given parameter index.- Parameters:
parameterIndex
- 1-basedforLongData
- 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 interfacejava.sql.PreparedStatement
- Overrides:
getMetaData
in classClientPreparedStatement
- Throws:
java.sql.SQLException
-
getParameterMetaData
public java.sql.ParameterMetaData getParameterMetaData() throws java.sql.SQLException- Specified by:
getParameterMetaData
in interfacejava.sql.PreparedStatement
- Overrides:
getParameterMetaData
in classClientPreparedStatement
- Throws:
java.sql.SQLException
-
isNull
public boolean isNull(int paramIndex)- Specified by:
isNull
in interfaceJdbcPreparedStatement
- Overrides:
isNull
in classClientPreparedStatement
-
realClose
public void realClose(boolean calledExplicitly, boolean closeOpenResults) throws java.sql.SQLExceptionDescription copied from class:StatementImpl
Closes this statement, and frees resources.- Specified by:
realClose
in interfaceJdbcPreparedStatement
- Overrides:
realClose
in classClientPreparedStatement
- 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.SQLExceptionTells 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 limitcreateStreamingResultSet
- 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 classClientPreparedStatement
- Throws:
java.sql.SQLException
-
setUnicodeStream
@Deprecated public void setUnicodeStream(int parameterIndex, java.io.InputStream x, int length) throws java.sql.SQLExceptionDeprecated.- Specified by:
setUnicodeStream
in interfacejava.sql.PreparedStatement
- Overrides:
setUnicodeStream
in classClientPreparedStatement
- Throws:
java.sql.SQLException
-
setURL
public void setURL(int parameterIndex, java.net.URL x) throws java.sql.SQLException- Specified by:
setURL
in interfacejava.sql.PreparedStatement
- Overrides:
setURL
in classClientPreparedStatement
- Throws:
java.sql.SQLException
-
getServerStatementId
public long getServerStatementId()- Overrides:
getServerStatementId
in classStatementImpl
-
setOneBatchedParameterSet
protected int setOneBatchedParameterSet(java.sql.PreparedStatement batchedStatement, int batchedParamIndex, java.lang.Object paramSet) throws java.sql.SQLException- Overrides:
setOneBatchedParameterSet
in classClientPreparedStatement
- Throws:
java.sql.SQLException
-
containsOnDuplicateKeyUpdateInSQL
protected boolean containsOnDuplicateKeyUpdateInSQL()- Overrides:
containsOnDuplicateKeyUpdateInSQL
in classClientPreparedStatement
-
prepareBatchedInsertSQL
protected ClientPreparedStatement prepareBatchedInsertSQL(JdbcConnection localConn, int numBatches) throws java.sql.SQLExceptionDescription copied from class:ClientPreparedStatement
Returns a prepared statement for the number of batched parameters, used when re-writing batch INSERTs.- Overrides:
prepareBatchedInsertSQL
in classClientPreparedStatement
- Parameters:
localConn
- the connection creating this statementnumBatches
- 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 interfacejava.sql.Statement
- Overrides:
setPoolable
in classStatementImpl
- Throws:
java.sql.SQLException
-