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 booleanisCacheableprotected booleanisCachedFields inherited from class com.mysql.cj.jdbc.ClientPreparedStatement
batchedValuesClause, batchHasPlainStatements, parameterMetaData, rewrittenBatchSizeFields 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 protectedServerPreparedStatement(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 voidaddBatch()java.lang.StringasSql(boolean quoteStreamsAndUnknowns)protected voidcheckBounds(int parameterIndex, int parameterIndexOffset)protected JdbcConnectioncheckClosed()Checks if closed() has been called, and throws an exception if sovoidclearParameters()voidclose()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 booleancontainsOnDuplicateKeyUpdateInSQL()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 ServerPreparedQueryBindValuegetBinding(int parameterIndex, boolean forLongData)Returns the structure representing the value that (can be)/(is) bound at the given parameter index.protected static ServerPreparedStatementgetInstance(JdbcConnection conn, java.lang.String sql, java.lang.String db, int resultSetType, int resultSetConcurrency)Creates a prepared statement instancejava.sql.ResultSetMetaDatagetMetaData()java.sql.ParameterMetaDatagetParameterMetaData()longgetServerStatementId()protected voidinitQuery()booleanisNull(int paramIndex)protected ClientPreparedStatementprepareBatchedInsertSQL(JdbcConnection localConn, int numBatches)Returns a prepared statement for the number of batched parameters, used when re-writing batch INSERTs.voidrealClose(boolean calledExplicitly, boolean closeOpenResults)Closes this statement, and frees resources.protected voidrePrepare()Used by Connection when auto-reconnecting to retrieve 'lost' prepared statements.protected ResultSetInternalMethodsserverExecute(int maxRowsToRetrieve, boolean createStreamingResultSet, ColumnDefinition metadata)Tells the server to execute this prepared statement with the current parameter bindings.protected voidserverPrepare(java.lang.String sql)protected voidsetClosed(boolean flag)protected intsetOneBatchedParameterSet(java.sql.PreparedStatement batchedStatement, int batchedParamIndex, java.lang.Object paramSet)voidsetPoolable(boolean poolable)voidsetUnicodeStream(int parameterIndex, java.io.InputStream x, int length)Deprecated.voidsetURL(int parameterIndex, java.net.URL x)java.lang.StringtoString()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, setTimestampMethods 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, unwrapMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.mysql.cj.jdbc.JdbcStatement
disableStreamingResults, enableStreamingResults, getExceptionInterceptor, getLocalInfileInputStream, getOpenResultSetCount, getQuery, removeOpenResultSet, setHoldResultsOpenOverClose, setLocalInfileInputStream, setPingTargetMethods 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, stopQueryTimerMethods 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:
initQueryin classClientPreparedStatement
-
toString
public java.lang.String toString()Description copied from class:ClientPreparedStatementReturns this PreparedStatement represented as a string.- Overrides:
toStringin classClientPreparedStatement- Returns:
- this PreparedStatement represented as a string.
-
addBatch
public void addBatch() throws java.sql.SQLException- Specified by:
addBatchin interfacejava.sql.PreparedStatement- Overrides:
addBatchin classClientPreparedStatement- Throws:
java.sql.SQLException
-
asSql
public java.lang.String asSql(boolean quoteStreamsAndUnknowns) throws java.sql.SQLException- Overrides:
asSqlin classClientPreparedStatement- Throws:
java.sql.SQLException
-
checkClosed
Description copied from class:StatementImplChecks if closed() has been called, and throws an exception if so- Overrides:
checkClosedin classStatementImpl- Returns:
- connection
-
clearParameters
public void clearParameters()- Specified by:
clearParametersin interfacejava.sql.PreparedStatement- Overrides:
clearParametersin classClientPreparedStatement
-
setClosed
protected void setClosed(boolean flag) -
close
public void close() throws java.sql.SQLExceptionDescription copied from class:StatementImplIn 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:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.sql.Statement- Overrides:
closein classStatementImpl- Throws:
java.sql.SQLException- if a database access error occurs
-
executeBatchSerially
protected long[] executeBatchSerially(int batchTimeout) throws java.sql.SQLExceptionDescription copied from class:ClientPreparedStatementExecutes the current batch of statements by executing them one-by-one.- Overrides:
executeBatchSeriallyin 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:ClientPreparedStatementActually execute the prepared statement. This is here so server-side PreparedStatements can re-use most of the code from this class.- Overrides:
executeInternalin 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:
getMetaDatain interfacejava.sql.PreparedStatement- Overrides:
getMetaDatain classClientPreparedStatement- Throws:
java.sql.SQLException
-
getParameterMetaData
public java.sql.ParameterMetaData getParameterMetaData() throws java.sql.SQLException- Specified by:
getParameterMetaDatain interfacejava.sql.PreparedStatement- Overrides:
getParameterMetaDatain classClientPreparedStatement- Throws:
java.sql.SQLException
-
isNull
public boolean isNull(int paramIndex)- Specified by:
isNullin interfaceJdbcPreparedStatement- Overrides:
isNullin classClientPreparedStatement
-
realClose
public void realClose(boolean calledExplicitly, boolean closeOpenResults) throws java.sql.SQLExceptionDescription copied from class:StatementImplCloses this statement, and frees resources.- Specified by:
realClosein interfaceJdbcPreparedStatement- Overrides:
realClosein 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:
checkBoundsin classClientPreparedStatement- Throws:
java.sql.SQLException
-
setUnicodeStream
@Deprecated public void setUnicodeStream(int parameterIndex, java.io.InputStream x, int length) throws java.sql.SQLExceptionDeprecated.- Specified by:
setUnicodeStreamin interfacejava.sql.PreparedStatement- Overrides:
setUnicodeStreamin classClientPreparedStatement- Throws:
java.sql.SQLException
-
setURL
public void setURL(int parameterIndex, java.net.URL x) throws java.sql.SQLException- Specified by:
setURLin interfacejava.sql.PreparedStatement- Overrides:
setURLin classClientPreparedStatement- Throws:
java.sql.SQLException
-
getServerStatementId
public long getServerStatementId()- Overrides:
getServerStatementIdin classStatementImpl
-
setOneBatchedParameterSet
protected int setOneBatchedParameterSet(java.sql.PreparedStatement batchedStatement, int batchedParamIndex, java.lang.Object paramSet) throws java.sql.SQLException- Overrides:
setOneBatchedParameterSetin classClientPreparedStatement- Throws:
java.sql.SQLException
-
containsOnDuplicateKeyUpdateInSQL
protected boolean containsOnDuplicateKeyUpdateInSQL()- Overrides:
containsOnDuplicateKeyUpdateInSQLin classClientPreparedStatement
-
prepareBatchedInsertSQL
protected ClientPreparedStatement prepareBatchedInsertSQL(JdbcConnection localConn, int numBatches) throws java.sql.SQLExceptionDescription copied from class:ClientPreparedStatementReturns a prepared statement for the number of batched parameters, used when re-writing batch INSERTs.- Overrides:
prepareBatchedInsertSQLin 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:
setPoolablein interfacejava.sql.Statement- Overrides:
setPoolablein classStatementImpl- Throws:
java.sql.SQLException
-