Class PreparedStatement
- All Implemented Interfaces:
Statement, Wrapper, AutoCloseable, PreparedStatement, Statement, Wrapper
- Direct Known Subclasses:
CallableStatement, JDBC4PreparedStatement, ServerPreparedStatement
Note: The setXXX methods for setting IN parameter values must specify types that are compatible with the defined SQL type of the input parameter. For instance, if the IN parameter has SQL type Integer, then setInt should be used.
If arbitrary parameter type conversions are required, then the setObject method should be used with a target SQL type.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classclass(package private) static interface(package private) class(package private) classstatic final classNested classes/interfaces inherited from class StatementImpl
StatementImpl.CancelTask -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intCommand index of currently executing batch command.protected Stringprotected booleanDoes the batch (if any) contain "plain" statements added by Statement.addBatch(String)?protected charWhat is the first character of the prepared statement (used to check for SELECT vs.protected booleanIs this query a LOAD DATA query?protected boolean[]protected intprotected StringThe SQL that was passed in to 'prepare'protected intThe number of parameters in this PreparedStatementprotected MysqlParameterMetadataprotected int[]Only used by statement interceptors at the moment to provide introspection of bound valuesprotected PreparedStatement.ParseInfoprotected intprotected booleanprotected booleanAre we using a version of MySQL where we can use 'true' boolean values?protected booleanFields inherited from class StatementImpl
batchedArgs, batchedGeneratedKeys, cancelTimeoutMutex, charConverter, charEncoding, clearWarningsCalled, connection, continueBatchOnError, currentCatalog, doEscapeProcessing, generatedKeysResults, holdResultsOpenOverClose, isClosed, lastInsertId, lastQueryIsOnDupKeyUpdate, maxFieldSize, maxRows, ON_DUPLICATE_KEY_UPDATE_CLAUSE, openResults, pedantic, physicalConnection, PING_MARKER, pingTarget, profileSQL, results, resultSetConcurrency, resultSetType, retrieveGeneratedKeys, sendFractionalSeconds, statementCounter, statementExecuting, statementId, timeoutInMillis, updateCount, useLegacyDatetimeCode, USES_VARIABLES_FALSE, USES_VARIABLES_TRUE, USES_VARIABLES_UNKNOWN, useUsageAdvisor, version5013OrNewer, warningChain, wasCancelled, wasCancelledByTimeoutFields inherited from interface Statement
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO -
Constructor Summary
ConstructorsConstructorDescriptionPreparedStatement(MySQLConnection conn, String catalog) Constructor used by server-side prepared statementsPreparedStatement(MySQLConnection conn, String sql, String catalog) Constructor for the PreparedStatement class.PreparedStatement(MySQLConnection conn, String sql, String catalog, PreparedStatement.ParseInfo cachedParseInfo) Creates a new PreparedStatement object. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBatch()JDBC 2.0 Add a set of parameters to the batch.voidasSql()asSql(boolean quoteStreamsAndUnknowns) protected static booleancanRewrite(String sql, boolean isOnDuplicateKeyUpdate, int locationOfOnDuplicateKeyUpdate, int statementStartPos) booleanprotected voidcheckBounds(int paramIndex, int parameterIndexOffset) protected booleanCheck to see if the statement is safe for read-only slaves after failover.voidJDBC 2.0 Make the set of commands in the current batch empty.voidIn general, parameter values remain in force for repeated used of a Statement.protected intcomputeBatchSize(int numBatchedArgs) Computes the optimum number of batched parameter lists to send without overflowing max_allowed_packet.protected long[]computeMaxParameterSetSizeAndBatchSize(int numBatchedArgs) Computes the maximum parameter set size, and entire batch size given the number of arguments in the batch.protected booleanprotected voidbooleanexecute()Some prepared statements return multiple results; the execute method handles these complex statements as well as the simpler form of statements handled by executeQuery and executeUpdateprotected long[]executeBatchedInserts(int batchTimeout) Rewrites the already prepared statement into a multi-value insert statement of 'statementsPerBatch' values and executes the entire batch using this new statement.protected long[]protected long[]executeBatchSerially(int batchTimeout) Executes the current batch of statements by executing them one-by-one.protected ResultSetInternalMethodsexecuteInternal(int maxRowsToRetrieve, Buffer sendPacket, boolean createStreamingResultSet, boolean queryIsSelectOnly, Field[] metadataFromCache, boolean isBatch) Actually execute the prepared statement.longJDBC 4.2 Same as PreparedStatement.executeUpdate() but returns long instead of int.protected long[]executePreparedBatchAsMultiStatement(int batchTimeout) Rewrites the already prepared statement into a multi-statement query of 'statementsPerBatch' values and executes the entire batch using this new statement.A Prepared SQL query is executed and its ResultSet is returnedintExecute a SQL INSERT, UPDATE or DELETE statement.protected longexecuteUpdateInternal(boolean clearBatchedGeneratedKeysAndWarnings, boolean isBatch) protected longexecuteUpdateInternal(byte[][] batchedParameterStrings, InputStream[] batchedParameterStreams, boolean[] batchedIsStream, int[] batchedStreamLengths, boolean[] batchedIsNull, boolean isReallyBatch) Added to allow batch-updatesprotected BufferCreates the packet that contains the query to be sent to the server.protected BufferfillSendPacket(byte[][] batchedParameterStrings, InputStream[] batchedParameterStreams, boolean[] batchedIsStream, int[] batchedStreamLengths) Creates the packet that contains the query to be sent to the server.byte[]getBytesRepresentation(int parameterIndex) protected byte[]getBytesRepresentationForBatch(int parameterIndex, int commandIndex) Get bytes representation for a parameter in a statement batch.getDateTime(String pattern) protected static PreparedStatementgetInstance(MySQLConnection conn, String catalog) Creates a prepared statement instance -- We need to provide factory-style methods so we can support both JDBC3 (and older) and JDBC4 runtimes, otherwise the class verifier complains when it tries to load JDBC4-only interface classes that are present in JDBC4 method signatures.protected static PreparedStatementgetInstance(MySQLConnection conn, String sql, String catalog) Creates a prepared statement instance -- We need to provide factory-style methods so we can support both JDBC3 (and older) and JDBC4 runtimes, otherwise the class verifier complains when it tries to load JDBC4-only interface classes that are present in JDBC4 method signatures.protected static PreparedStatementgetInstance(MySQLConnection conn, String sql, String catalog, PreparedStatement.ParseInfo cachedParseInfo) Creates a prepared statement instance -- We need to provide factory-style methods so we can support both JDBC3 (and older) and JDBC4 runtimes, otherwise the class verifier complains when it tries to load JDBC4-only interface classes that are present in JDBC4 method signatures.protected intThe number, types and properties of a ResultSet's columns are provided by the getMetaData method.protected intFor calling stored functions, this will be -1 as we don't really count the first '?'(package private) PreparedStatement.ParseInfointintgetUpdateCount returns the current result as an update count, if the result is a ResultSet or there are no more results, -1 is returned.protected String(package private) booleanisNull(int paramIndex) protected booleanprotected PreparedStatementprepareBatchedInsertSQL(MySQLConnection localConn, int numBatches) Returns a prepared statement for the number of batched parameters, used when re-writing batch INSERTs.protected static intReads length bytes from reader into buf.protected voidrealClose(boolean calledExplicitly, boolean closeOpenResults) Closes this statement, releasing all resourcesvoidJDBC 2.0 Set an Array parameter.voidsetAsciiStream(int parameterIndex, InputStream x) voidsetAsciiStream(int parameterIndex, InputStream x, int length) When a very large ASCII value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.InputStream.voidsetAsciiStream(int parameterIndex, InputStream x, long length) voidsetBigDecimal(int parameterIndex, BigDecimal x) Set a parameter to a java.math.BigDecimal value.voidsetBinaryStream(int parameterIndex, InputStream x) voidsetBinaryStream(int parameterIndex, InputStream x, int length) When a very large binary value is input to a LONGVARBINARY parameter, it may be more practical to send it via a java.io.InputStream.voidsetBinaryStream(int parameterIndex, InputStream x, long length) voidsetBlob(int parameterIndex, InputStream inputStream) voidsetBlob(int parameterIndex, InputStream inputStream, long length) voidJDBC 2.0 Set a BLOB parameter.voidsetBoolean(int parameterIndex, boolean x) Set a parameter to a Java boolean value.voidsetByte(int parameterIndex, byte x) Set a parameter to a Java byte value.voidsetBytes(int parameterIndex, byte[] x) Set a parameter to a Java array of bytes.protected voidsetBytes(int parameterIndex, byte[] x, boolean checkForIntroducer, boolean escapeForMBChars) protected voidsetBytesNoEscape(int parameterIndex, byte[] parameterAsBytes) Used by updatable result sets for refreshRow() because the parameter has already been escaped for updater or inserter prepared statements.protected voidsetBytesNoEscapeNoQuotes(int parameterIndex, byte[] parameterAsBytes) voidsetCharacterStream(int parameterIndex, Reader reader) voidsetCharacterStream(int parameterIndex, Reader reader, int length) JDBC 2.0 When a very large UNICODE value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.Reader.voidsetCharacterStream(int parameterIndex, Reader reader, long length) voidvoidvoidJDBC 2.0 Set a CLOB parameter.voidSet a parameter to a java.sql.Date value.voidSet a parameter to a java.sql.Date value.voidsetDouble(int parameterIndex, double x) Set a parameter to a Java double value.voidsetFloat(int parameterIndex, float x) Set a parameter to a Java float value.voidsetInt(int parameterIndex, int x) Set a parameter to a Java int value.protected final voidsetInternal(int paramIndex, byte[] val) protected final voidsetInternal(int paramIndex, String val) voidsetLong(int parameterIndex, long x) Set a parameter to a Java long value.voidsetNCharacterStream(int parameterIndex, Reader value) voidsetNCharacterStream(int parameterIndex, Reader reader, long length) JDBC 2.0 When a very large UNICODE value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.Reader.voidvoidJDBC 4.0 Set a NCLOB parameter.voidsetNString(int parameterIndex, String x) Set a parameter to a Java String value.voidsetNull(int parameterIndex, int sqlType) Set a parameter to SQL NULLvoidSet a parameter to SQL NULL.voidvoidvoidSet the value of a parameter using an object; use the java.lang equivalent objects for integral values.protected intsetOneBatchedParameterSet(PreparedStatement batchedStatement, int batchedParamIndex, Object paramSet) voidJDBC 2.0 Set a REF(<structured-type>) parameter.protected voidsetRetrieveGeneratedKeys(boolean flag) voidsetShort(int parameterIndex, short x) Set a parameter to a Java short value.voidSet a parameter to a Java String value.voidSet a parameter to a java.sql.Time value.voidSet a parameter to a java.sql.Time value.voidsetTimestamp(int parameterIndex, Timestamp x) Set a parameter to a java.sql.Timestamp value.voidsetTimestamp(int parameterIndex, Timestamp x, Calendar cal) Set a parameter to a java.sql.Timestamp value.protected voidsetTimestampInternal(int parameterIndex, Timestamp x, Calendar targetCalendar, TimeZone tz, boolean rollForward, int fractionalLength, boolean useSSPSCompatibleTimezoneShift) Set a parameter to a java.sql.Timestamp value.voidsetUnicodeStream(int parameterIndex, InputStream x, int length) Deprecated.voidtoString()Returns this PreparedStatement represented as a string.Methods inherited from class StatementImpl
cancel, checkClosed, checkForDml, checkNullOrEmptyQuery, clearWarnings, close, closeAllOpenResults, closeOnCompletion, 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, getCalendarInstanceForSessionOrNew, getConnection, getExceptionInterceptor, getFetchDirection, getFetchSize, getGeneratedKeys, getGeneratedKeysInternal, getGeneratedKeysInternal, getId, getLargeMaxRows, getLargeUpdateCount, getLastInsertID, getLocalInfileInputStream, getLongUpdateCount, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getOnDuplicateKeyLocation, getOpenResultSetCount, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetInternal, getResultSetType, getWarnings, handleExceptionForBatch, hasDeadlockOrTimeoutRolledBackTx, implicitlyCloseAllOpenResults, isClosed, isCloseOnCompletion, isCursorRequired, isPoolable, isWrapperFor, processMultiCountsAndKeys, removeOpenResultSet, resetCancelledState, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setHoldResultsOpenOverClose, setLargeMaxRows, setLocalInfileInputStream, setMaxFieldSize, setMaxRows, setPingTarget, setPoolable, setQueryTimeout, setResultSetConcurrency, setResultSetType, setupStreamingTimeout, statementBegins, unwrapMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface PreparedStatement
setNClob, setObject, setObject, setRowId, setSQLXMLMethods inherited from interface Statement
cancel, clearWarnings, close, 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, setPoolable, setQueryTimeoutMethods inherited from interface Wrapper
isWrapperFor, unwrap
-
Field Details
-
batchHasPlainStatements
protected boolean batchHasPlainStatementsDoes the batch (if any) contain "plain" statements added by Statement.addBatch(String)? If so, we can't re-write it to use multi-value or multi-queries. -
firstCharOfStmt
protected char firstCharOfStmtWhat is the first character of the prepared statement (used to check for SELECT vs. INSERT/UPDATE/DELETE) -
isLoadDataQuery
protected boolean isLoadDataQueryIs this query a LOAD DATA query? -
isNull
protected boolean[] isNull -
numberOfExecutions
protected int numberOfExecutions -
originalSql
The SQL that was passed in to 'prepare' -
parameterCount
protected int parameterCountThe number of parameters in this PreparedStatement -
parameterMetaData
-
parameterTypes
protected int[] parameterTypesOnly used by statement interceptors at the moment to provide introspection of bound values -
parseInfo
-
useTrueBoolean
protected boolean useTrueBooleanAre we using a version of MySQL where we can use 'true' boolean values? -
usingAnsiMode
protected boolean usingAnsiMode -
batchedValuesClause
-
batchCommandIndex
protected int batchCommandIndexCommand index of currently executing batch command. -
serverSupportsFracSecs
protected boolean serverSupportsFracSecs -
rewrittenBatchSize
protected int rewrittenBatchSize
-
-
Constructor Details
-
PreparedStatement
Constructor used by server-side prepared statements- Parameters:
conn- the connection that created uscatalog- the catalog in use when we were created- Throws:
SQLException- if an error occurs
-
PreparedStatement
Constructor for the PreparedStatement class.- Parameters:
conn- the connection creating this statementsql- the SQL for this statementcatalog- the catalog/database this statement should be issued against- Throws:
SQLException- if a database error occurs.
-
PreparedStatement
public PreparedStatement(MySQLConnection conn, String sql, String catalog, PreparedStatement.ParseInfo cachedParseInfo) throws SQLException Creates a new PreparedStatement object.- Parameters:
conn- the connection creating this statementsql- the SQL for this statementcatalog- the catalog/database this statement should be issued againstcachedParseInfo- already created parseInfo.- Throws:
SQLException
-
-
Method Details
-
readFully
Reads length bytes from reader into buf. Blocks until enough input is available- Parameters:
reader-buf-length-- Throws:
IOException
-
getInstance
protected static PreparedStatement getInstance(MySQLConnection conn, String catalog) throws SQLException Creates a prepared statement instance -- We need to provide factory-style methods so we can support both JDBC3 (and older) and JDBC4 runtimes, otherwise the class verifier complains when it tries to load JDBC4-only interface classes that are present in JDBC4 method signatures.- Throws:
SQLException
-
getInstance
protected static PreparedStatement getInstance(MySQLConnection conn, String sql, String catalog) throws SQLException Creates a prepared statement instance -- We need to provide factory-style methods so we can support both JDBC3 (and older) and JDBC4 runtimes, otherwise the class verifier complains when it tries to load JDBC4-only interface classes that are present in JDBC4 method signatures.- Throws:
SQLException
-
getInstance
protected static PreparedStatement getInstance(MySQLConnection conn, String sql, String catalog, PreparedStatement.ParseInfo cachedParseInfo) throws SQLException Creates a prepared statement instance -- We need to provide factory-style methods so we can support both JDBC3 (and older) and JDBC4 runtimes, otherwise the class verifier complains when it tries to load JDBC4-only interface classes that are present in JDBC4 method signatures.- Throws:
SQLException
-
detectFractionalSecondsSupport
- Throws:
SQLException
-
addBatch
JDBC 2.0 Add a set of parameters to the batch.- Specified by:
addBatchin interfacePreparedStatement- Throws:
SQLException- if a database-access error occurs.- See Also:
-
addBatch
- Specified by:
addBatchin interfaceStatement- Overrides:
addBatchin classStatementImpl- Parameters:
sql-- Throws:
SQLException
-
asSql
- Throws:
SQLException
-
asSql
- Throws:
SQLException
-
clearBatch
Description copied from class:StatementImplJDBC 2.0 Make the set of commands in the current batch empty. This method is optional.- Specified by:
clearBatchin interfaceStatement- Overrides:
clearBatchin classStatementImpl- Throws:
SQLException- if a database-access error occurs, or the driver does not support batch statements
-
clearParameters
In general, parameter values remain in force for repeated used 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 clearParameters- Specified by:
clearParametersin interfacePreparedStatement- Throws:
SQLException- if a database access error occurs
-
checkReadOnlySafeStatement
Check to see if the statement is safe for read-only slaves after failover.- Returns:
- true if safe for read-only.
- Throws:
SQLException
-
execute
Some prepared statements return multiple results; the execute method handles these complex statements as well as the simpler form of statements handled by executeQuery and executeUpdate- Specified by:
executein interfacePreparedStatement- Returns:
- true if the next result is a ResultSet; false if it is an update count or there are no more results
- Throws:
SQLException- if a database access error occurs
-
executeBatchInternal
- Overrides:
executeBatchInternalin classStatementImpl- Throws:
SQLException
-
canRewriteAsMultiValueInsertAtSqlLevel
- Throws:
SQLException
-
getLocationOfOnDuplicateKeyUpdate
- Throws:
SQLException
-
executePreparedBatchAsMultiStatement
Rewrites the already prepared statement into a multi-statement query of 'statementsPerBatch' values and executes the entire batch using this new statement.- Returns:
- update counts in the same fashion as executeBatch()
- Throws:
SQLException
-
executeBatchedInserts
Rewrites the already prepared statement into a multi-value insert statement of 'statementsPerBatch' values and executes the entire batch using this new statement.- Returns:
- update counts in the same fashion as executeBatch()
- Throws:
SQLException
-
getValuesClause
- Throws:
SQLException
-
computeBatchSize
Computes the optimum number of batched parameter lists to send without overflowing max_allowed_packet.- Parameters:
numBatchedArgs-- Throws:
SQLException
-
computeMaxParameterSetSizeAndBatchSize
Computes the maximum parameter set size, and entire batch size given the number of arguments in the batch.- Throws:
SQLException
-
executeBatchSerially
Executes the current batch of statements by executing them one-by-one.- Returns:
- a list of update counts
- Throws:
SQLException- if an error occurs
-
getDateTime
-
executeInternal
protected ResultSetInternalMethods executeInternal(int maxRowsToRetrieve, Buffer sendPacket, boolean createStreamingResultSet, boolean queryIsSelectOnly, Field[] metadataFromCache, boolean isBatch) throws SQLException Actually execute the prepared statement. This is here so server-side PreparedStatements can re-use most of the code from this class.- 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?unpackFields-- Returns:
- the results as a ResultSet
- Throws:
SQLException- if an error occurs.
-
executeQuery
A Prepared SQL query is executed and its ResultSet is returned- Specified by:
executeQueryin interfacePreparedStatement- Returns:
- a ResultSet that contains the data produced by the query - never null
- Throws:
SQLException- if a database access error occurs
-
executeUpdate
Execute a SQL INSERT, UPDATE or DELETE statement. In addition, SQL statements that return nothing such as SQL DDL statements can be executed.- Specified by:
executeUpdatein interfacePreparedStatement- Returns:
- either the row count for INSERT, UPDATE or DELETE; or 0 for SQL statements that return nothing.
- Throws:
SQLException- if a database access error occurs
-
executeUpdateInternal
protected long executeUpdateInternal(boolean clearBatchedGeneratedKeysAndWarnings, boolean isBatch) throws SQLException - Throws:
SQLException
-
executeUpdateInternal
protected long executeUpdateInternal(byte[][] batchedParameterStrings, InputStream[] batchedParameterStreams, boolean[] batchedIsStream, int[] batchedStreamLengths, boolean[] batchedIsNull, boolean isReallyBatch) throws SQLException Added to allow batch-updates- Parameters:
batchedParameterStrings- string values used in single statementbatchedParameterStreams- stream values used in single statementbatchedIsStream- flags for streams used in single statementbatchedStreamLengths- lengths of streams to be read.batchedIsNull- flags for parameters that are null- Returns:
- the update count
- Throws:
SQLException- if a database error occurs
-
containsOnDuplicateKeyUpdateInSQL
protected boolean containsOnDuplicateKeyUpdateInSQL() -
fillSendPacket
Creates the packet that contains the query to be sent to the server.- Returns:
- A Buffer filled with the query representing the PreparedStatement.
- Throws:
SQLException- if an error occurs.
-
fillSendPacket
protected Buffer fillSendPacket(byte[][] batchedParameterStrings, InputStream[] batchedParameterStreams, boolean[] batchedIsStream, int[] batchedStreamLengths) throws SQLException Creates the packet that contains the query to be sent to the server.- Parameters:
batchedParameterStrings- the parameters as stringsbatchedParameterStreams- the parameters as streamsbatchedIsStream- is the given parameter a stream?batchedStreamLengths- the lengths of the streams (if appropriate)- Returns:
- a Buffer filled with the query that represents this statement
- Throws:
SQLException- if an error occurs.
-
prepareBatchedInsertSQL
protected PreparedStatement prepareBatchedInsertSQL(MySQLConnection localConn, int numBatches) throws SQLException Returns a prepared statement for the number of batched parameters, used when re-writing batch INSERTs.- Throws:
SQLException
-
setRetrieveGeneratedKeys
- Throws:
SQLException
-
getRewrittenBatchSize
public int getRewrittenBatchSize() -
getNonRewrittenSql
- Throws:
SQLException
-
getBytesRepresentation
- Parameters:
parameterIndex-- Throws:
SQLException
-
getBytesRepresentationForBatch
protected byte[] getBytesRepresentationForBatch(int parameterIndex, int commandIndex) throws SQLException Get bytes representation for a parameter in a statement batch.- Parameters:
parameterIndex-commandIndex-- Throws:
SQLException
-
getMetaData
The number, types and properties of a ResultSet's columns are provided by the getMetaData method.- Specified by:
getMetaDatain interfacePreparedStatement- Returns:
- the description of a ResultSet's columns
- Throws:
SQLException- if a database-access error occurs.
-
isSelectQuery
- Throws:
SQLException
-
getParameterMetaData
- Specified by:
getParameterMetaDatain interfacePreparedStatement- Throws:
SQLException- See Also:
-
getParseInfo
PreparedStatement.ParseInfo getParseInfo() -
isNull
- Throws:
SQLException
-
realClose
Closes this statement, releasing all resources- Overrides:
realClosein classStatementImpl- Parameters:
calledExplicitly- was this called by close()?- Throws:
SQLException- if an error occurs
-
setArray
JDBC 2.0 Set an Array parameter.- Specified by:
setArrayin interfacePreparedStatement- Parameters:
i- the first parameter is 1, the second is 2, ...x- an object representing an SQL array- Throws:
SQLException- because this method is not implemented.NotImplemented
-
setAsciiStream
When a very large ASCII value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.InputStream. JDBC will read the data from the stream as needed, until it reaches end-of-file. The JDBC driver will do any necessary conversion from ASCII to the database char format.Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.
- Specified by:
setAsciiStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1...x- the parameter valuelength- the number of bytes in the stream- Throws:
SQLException- if a database access error occurs
-
setBigDecimal
Set a parameter to a java.math.BigDecimal value. The driver converts this to a SQL NUMERIC value when it sends it to the database.- Specified by:
setBigDecimalin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setBinaryStream
When a very large binary value is input to a LONGVARBINARY parameter, it may be more practical to send it via a java.io.InputStream. JDBC will read the data from the stream as needed, until it reaches end-of-file.Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.
- Specified by:
setBinaryStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1...x- the parameter valuelength- the number of bytes to read from the stream (ignored)- Throws:
SQLException- if a database access error occurs
-
setBlob
- Specified by:
setBlobin interfacePreparedStatement- Throws:
SQLException
-
setBlob
JDBC 2.0 Set a BLOB parameter.- Specified by:
setBlobin interfacePreparedStatement- Parameters:
i- the first parameter is 1, the second is 2, ...x- an object representing a BLOB- Throws:
SQLException- if a database error occurs
-
setBoolean
Set a parameter to a Java boolean value. The driver converts this to a SQL BIT value when it sends it to the database.- Specified by:
setBooleanin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setByte
Set a parameter to a Java byte value. The driver converts this to a SQL TINYINT value when it sends it to the database.- Specified by:
setBytein interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setBytes
Set a parameter to a Java array of bytes. The driver converts this to a SQL VARBINARY or LONGVARBINARY (depending on the argument's size relative to the driver's limits on VARBINARYs) when it sends it to the database.- Specified by:
setBytesin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setBytes
protected void setBytes(int parameterIndex, byte[] x, boolean checkForIntroducer, boolean escapeForMBChars) throws SQLException - Throws:
SQLException
-
setBytesNoEscape
Used by updatable result sets for refreshRow() because the parameter has already been escaped for updater or inserter prepared statements.- Parameters:
parameterIndex- the parameter to set.parameterAsBytes- the parameter as a string.- Throws:
SQLException- if an error occurs
-
setBytesNoEscapeNoQuotes
protected void setBytesNoEscapeNoQuotes(int parameterIndex, byte[] parameterAsBytes) throws SQLException - Throws:
SQLException
-
setCharacterStream
JDBC 2.0 When a very large UNICODE value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.Reader. JDBC will read the data from the stream as needed, until it reaches end-of-file. The JDBC driver will do any necessary conversion from UNICODE to the database char format.Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.
- Specified by:
setCharacterStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...reader- the java reader which contains the UNICODE datalength- the number of characters in the stream- Throws:
SQLException- if a database-access error occurs.
-
setClob
JDBC 2.0 Set a CLOB parameter.- Specified by:
setClobin interfacePreparedStatement- Parameters:
i- the first parameter is 1, the second is 2, ...x- an object representing a CLOB- Throws:
SQLException- if a database error occurs
-
setDate
Set a parameter to a java.sql.Date value. The driver converts this to a SQL DATE value when it sends it to the database.- Specified by:
setDatein interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setDate
Set a parameter to a java.sql.Date value. The driver converts this to a SQL DATE value when it sends it to the database.- Specified by:
setDatein interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter valuecal- the calendar to interpret the date with- Throws:
SQLException- if a database-access error occurs.
-
setDouble
Set a parameter to a Java double value. The driver converts this to a SQL DOUBLE value when it sends it to the database- Specified by:
setDoublein interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setFloat
Set a parameter to a Java float value. The driver converts this to a SQL FLOAT value when it sends it to the database.- Specified by:
setFloatin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setInt
Set a parameter to a Java int value. The driver converts this to a SQL INTEGER value when it sends it to the database.- Specified by:
setIntin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setInternal
- Throws:
SQLException
-
checkBounds
- Throws:
SQLException
-
setInternal
- Throws:
SQLException
-
setLong
Set a parameter to a Java long value. The driver converts this to a SQL BIGINT value when it sends it to the database.- Specified by:
setLongin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setNull
Set a parameter to SQL NULLNote: You must specify the parameters SQL type (although MySQL ignores it)
- Specified by:
setNullin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, etc...sqlType- the SQL type code defined in java.sql.Types- Throws:
SQLException- if a database access error occurs
-
setNull
Set a parameter to SQL NULL.Note: You must specify the parameter's SQL type.
- Specified by:
setNullin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...sqlType- SQL type code defined by java.sql.Typesarg- argument parameters for null- Throws:
SQLException- if a database-access error occurs.
-
setObject
- Specified by:
setObjectin interfacePreparedStatement- Throws:
SQLException
-
setObject
public void setObject(int parameterIndex, Object parameterObj, int targetSqlType) throws SQLException - Specified by:
setObjectin interfacePreparedStatement- Parameters:
parameterIndex-parameterObj-targetSqlType-- Throws:
SQLException
-
setObject
public void setObject(int parameterIndex, Object parameterObj, int targetSqlType, int scale) throws SQLException Set the value of a parameter using an object; use the java.lang equivalent objects for integral values.The given Java object will be converted to the targetSqlType before being sent to the database.
note that this method may be used to pass database-specific abstract data types. This is done by using a Driver-specific Java type and using a targetSqlType of java.sql.Types.OTHER
- Specified by:
setObjectin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1...parameterObj- the object containing the input parameter valuetargetSqlType- The SQL type to be send to the databasescale- For java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types this is the number of digits after the decimal. For all other types this value will be ignored.- Throws:
SQLException- if a database access error occurs
-
setOneBatchedParameterSet
protected int setOneBatchedParameterSet(PreparedStatement batchedStatement, int batchedParamIndex, Object paramSet) throws SQLException - Throws:
SQLException
-
setRef
JDBC 2.0 Set a REF(<structured-type>) parameter.- Specified by:
setRefin interfacePreparedStatement- Parameters:
i- the first parameter is 1, the second is 2, ...x- an object representing data of an SQL REF Type- Throws:
SQLException- if a database error occursNotImplemented
-
setShort
Set a parameter to a Java short value. The driver converts this to a SQL SMALLINT value when it sends it to the database.- Specified by:
setShortin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setString
Set a parameter to a Java String value. The driver converts this to a SQL VARCHAR or LONGVARCHAR value (depending on the arguments size relative to the driver's limits on VARCHARs) when it sends it to the database.- Specified by:
setStringin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setTime
Set a parameter to a java.sql.Time value. The driver converts this to a SQL TIME value when it sends it to the database.- Specified by:
setTimein interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter valuecal- the cal specifying the timezone- Throws:
SQLException- if a database-access error occurs.
-
setTime
Set a parameter to a java.sql.Time value. The driver converts this to a SQL TIME value when it sends it to the database.- Specified by:
setTimein interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1...));x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setTimestamp
Set a parameter to a java.sql.Timestamp value. The driver converts this to a SQL TIMESTAMP value when it sends it to the database.- Specified by:
setTimestampin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter valuecal- the calendar specifying the timezone to use- Throws:
SQLException- if a database-access error occurs.
-
setTimestamp
Set a parameter to a java.sql.Timestamp value. The driver converts this to a SQL TIMESTAMP value when it sends it to the database.- Specified by:
setTimestampin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setTimestampInternal
protected void setTimestampInternal(int parameterIndex, Timestamp x, Calendar targetCalendar, TimeZone tz, boolean rollForward, int fractionalLength, boolean useSSPSCompatibleTimezoneShift) throws SQLException Set a parameter to a java.sql.Timestamp value. The driver converts this to a SQL TIMESTAMP value when it sends it to the database.- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...x- the parameter valuetz- the timezone to use- Throws:
SQLException- if a database-access error occurs.
-
setUnicodeStream
@Deprecated public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException Deprecated.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. JDBC will read the data from the stream as needed, until it reaches end-of-file. The JDBC driver will do any necessary conversion from UNICODE to the database char format.Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.
- Specified by:
setUnicodeStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1...x- the parameter valuelength- the number of bytes to read from the stream- Throws:
SQLException- if a database access error occurs
-
setURL
- Specified by:
setURLin interfacePreparedStatement- Throws:
SQLException- See Also:
-
toString
-
getParameterIndexOffset
protected int getParameterIndexOffset()For calling stored functions, this will be -1 as we don't really count the first '?' parameter marker, it's only syntax, but JDBC counts it as #1, otherwise it will return 0 -
setAsciiStream
- Specified by:
setAsciiStreamin interfacePreparedStatement- Throws:
SQLException
-
setAsciiStream
- Specified by:
setAsciiStreamin interfacePreparedStatement- Throws:
SQLException
-
setBinaryStream
- Specified by:
setBinaryStreamin interfacePreparedStatement- Throws:
SQLException
-
setBinaryStream
- Specified by:
setBinaryStreamin interfacePreparedStatement- Throws:
SQLException
-
setBlob
- Specified by:
setBlobin interfacePreparedStatement- Throws:
SQLException
-
setCharacterStream
- Specified by:
setCharacterStreamin interfacePreparedStatement- Throws:
SQLException
-
setCharacterStream
- Specified by:
setCharacterStreamin interfacePreparedStatement- Throws:
SQLException
-
setClob
- Specified by:
setClobin interfacePreparedStatement- Throws:
SQLException
-
setClob
- Specified by:
setClobin interfacePreparedStatement- Throws:
SQLException
-
setNCharacterStream
- Specified by:
setNCharacterStreamin interfacePreparedStatement- Throws:
SQLException
-
setNString
Set a parameter to a Java String value. The driver converts this to a SQL VARCHAR or LONGVARCHAR value with introducer _utf8 (depending on the arguments size relative to the driver's limits on VARCHARs) when it sends it to the database. If charset is set as utf8, this method just call setString.- Specified by:
setNStringin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1...x- the parameter value- Throws:
SQLException- if a database access error occurs
-
setNCharacterStream
JDBC 2.0 When a very large UNICODE value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.Reader. JDBC will read the data from the stream as needed, until it reaches end-of-file. The JDBC driver will do any necessary conversion from UNICODE to the database char format.Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.
- Specified by:
setNCharacterStreamin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...reader- the java reader which contains the UNICODE datalength- the number of characters in the stream- Throws:
SQLException- if a database-access error occurs.
-
setNClob
- Specified by:
setNClobin interfacePreparedStatement- Throws:
SQLException
-
setNClob
JDBC 4.0 Set a NCLOB parameter.- Specified by:
setNClobin interfacePreparedStatement- Parameters:
parameterIndex- the first parameter is 1, the second is 2, ...reader- the java reader which contains the UNICODE datalength- the number of characters in the stream- Throws:
SQLException- if a database error occurs
-
getParameterBindings
- Throws:
SQLException
-
getPreparedSql
-
getUpdateCount
Description copied from class:StatementImplgetUpdateCount 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.- Specified by:
getUpdateCountin interfaceStatement- Overrides:
getUpdateCountin classStatementImpl- Returns:
- the current result as an update count.
- Throws:
SQLException- if a database access error occurs
-
canRewrite
protected static boolean canRewrite(String sql, boolean isOnDuplicateKeyUpdate, int locationOfOnDuplicateKeyUpdate, int statementStartPos) -
executeLargeUpdate
JDBC 4.2 Same as PreparedStatement.executeUpdate() but returns long instead of int.- Specified by:
executeLargeUpdatein interfacePreparedStatement- Throws:
SQLException
-