Class ServerSidePreparedStatement
- All Implemented Interfaces:
AutoCloseable,Cloneable,PreparedStatement,Statement,Wrapper
- Direct Known Subclasses:
CallableProcedureStatement
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Map<Integer, ParameterHolder> private static final Loggerprivate MariaDbResultSetMetaDataprivate booleanprotected intprivate MariaDbParameterMetaDataprivate List<ParameterHolder[]> private ServerPrepareResultprivate StringFields inherited from class org.mariadb.jdbc.BasePrepareStatement
autoGeneratedKeys, hasLongData, SPEC_ISO_ZONED_DATE_TIMEFields inherited from class org.mariadb.jdbc.MariaDbStatement
canUseServerTimeout, closed, connection, executing, fetchSize, lock, maxRows, options, protocol, queryTimeout, results, resultSetConcurrency, resultSetScrollTypeFields inherited from interface java.sql.Statement
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO -
Constructor Summary
ConstructorsConstructorDescriptionServerSidePreparedStatement(MariaDbConnection connection, String sql, int resultSetScrollType, int resultSetConcurrency, int autoGeneratedKeys) Constructor for creating Server prepared statement. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBatch()voidAdd batch.voidEmpties thisStatementobject's current list of SQL send.voidclone(MariaDbConnection connection) Clone statement.voidclose()Releases thisStatementobject's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed.booleanexecute()int[]Submits a batch of send to the database for execution and if all send execute successfully, returns an array of update counts.private voidexecuteBatchInternal(int queryParameterSize) protected booleanexecuteInternal(int fetchSize) long[]Execute batch, like executeBatch(), with returning results with long[].private voidexecuteQueryPrologue(ServerPrepareResult serverPrepareResult) intprotected intRetrieves the number, types and properties of thisPreparedStatementobject's parameters.longPermit to retrieve current connection thread id, or -1 if unknown.private voidprivate voidvoidsetParameter(int parameterIndex, ParameterHolder holder) toString()Return sql String value.protected voidMethods inherited from class org.mariadb.jdbc.BasePrepareStatement
executeLargeUpdate, setArray, setAsciiStream, setAsciiStream, setAsciiStream, setBigDecimal, setBinaryStream, setBinaryStream, setBinaryStream, setBlob, setBlob, setBlob, setBoolean, setByte, setBytes, 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, setRowId, setShort, setSQLXML, setString, setTime, setTime, setTimestamp, setTimestamp, setUnicodeStream, setURLMethods inherited from class org.mariadb.jdbc.MariaDbStatement
cancel, checkClose, checkCloseOnCompletion, clearWarnings, closeOnCompletion, execute, execute, execute, execute, executeBatchEpilogue, executeBatchExceptionEpilogue, executeEpilogue, executeExceptionEpilogue, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeQuery, executeQueryPrologue, executeUpdate, executeUpdate, executeUpdate, executeUpdate, getConnection, getFetchDirection, getFetchSize, getGeneratedKeys, getLargeMaxRows, getLargeUpdateCount, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, isClosed, isCloseOnCompletion, isPoolable, isWrapperFor, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setLargeMaxRows, setLocalInfileInputStream, setMaxFieldSize, setMaxRows, setPoolable, setQueryTimeout, setTimerTask, skipMoreResults, testExecute, unwrapMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.sql.Statement
cancel, clearWarnings, closeOnCompletion, enquoteIdentifier, enquoteLiteral, enquoteNCharLiteral, execute, execute, execute, execute, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeQuery, executeUpdate, executeUpdate, executeUpdate, executeUpdate, getConnection, getFetchDirection, getFetchSize, getGeneratedKeys, getLargeMaxRows, getLargeUpdateCount, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, isClosed, isCloseOnCompletion, isPoolable, isSimpleIdentifier, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setLargeMaxRows, setMaxFieldSize, setMaxRows, setPoolable, setQueryTimeoutMethods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
-
Field Details
-
logger
-
parameterCount
protected int parameterCount -
sql
-
serverPrepareResult
-
metadata
-
parameterMetaData
-
currentParameterHolder
-
queryParameters
-
mustExecuteOnMaster
private boolean mustExecuteOnMaster
-
-
Constructor Details
-
ServerSidePreparedStatement
public ServerSidePreparedStatement(MariaDbConnection connection, String sql, int resultSetScrollType, int resultSetConcurrency, int autoGeneratedKeys) throws SQLException Constructor for creating Server prepared statement.- Parameters:
connection- current connectionsql- Sql String to prepareresultSetScrollType- one of the followingResultSetconstants:ResultSet.TYPE_FORWARD_ONLY,ResultSet.TYPE_SCROLL_INSENSITIVE, orResultSet.TYPE_SCROLL_SENSITIVEresultSetConcurrency- a concurrency type; one ofResultSet.CONCUR_READ_ONLYorResultSet.CONCUR_UPDATABLEautoGeneratedKeys- a flag indicating whether auto-generated keys should be returned; one ofStatement.RETURN_GENERATED_KEYSorStatement.NO_GENERATED_KEYS- Throws:
SQLException- exception
-
-
Method Details
-
clone
public ServerSidePreparedStatement clone(MariaDbConnection connection) throws CloneNotSupportedException Clone statement.- Overrides:
clonein classBasePrepareStatement- Parameters:
connection- connection- Returns:
- Clone statement.
- Throws:
CloneNotSupportedException- if any error occur.
-
prepare
- Throws:
SQLException
-
setMetaFromResult
private void setMetaFromResult() -
setParameter
- Specified by:
setParameterin classBasePrepareStatement- Throws:
SQLException
-
addBatch
- Specified by:
addBatchin interfacePreparedStatement- Throws:
SQLException
-
addBatch
Add batch.- Specified by:
addBatchin interfaceStatement- Overrides:
addBatchin classMariaDbStatement- Parameters:
sql- typically this is a SQLINSERTorUPDATEstatement- Throws:
SQLException- every time since that method is forbidden on prepareStatement- See Also:
-
clearBatch
public void clearBatch()Description copied from class:MariaDbStatementEmpties thisStatementobject's current list of SQL send.- Specified by:
clearBatchin interfaceStatement- Overrides:
clearBatchin classMariaDbStatement- See Also:
-
getParameterMetaData
Description copied from class:BasePrepareStatementRetrieves the number, types and properties of thisPreparedStatementobject's parameters.- Specified by:
getParameterMetaDatain interfacePreparedStatement- Specified by:
getParameterMetaDatain classBasePrepareStatement- Returns:
- a
ParameterMetaDataobject that contains information about the number, types and properties for each parameter marker of thisPreparedStatementobject - Throws:
SQLException- if a database access error occurs or this method is called on a closedPreparedStatement- See Also:
-
getMetaData
- Specified by:
getMetaDatain interfacePreparedStatement- Throws:
SQLException
-
executeBatch
Submits a batch of send to the database for execution and if all send execute successfully, returns an array of update counts. The
intelements of the array that is returned are ordered to correspond to the send in the batch, which are ordered according to the order in which they were added to the batch. The elements in the array returned by the methodexecuteBatchmay be one of the following:- A number greater than or equal to zero -- indicates that the command was processed successfully and is an update count giving the number of rows in the database that were affected by the command's execution
- A value of
SUCCESS_NO_INFO-- indicates that the command was processed successfully but that the number of rows affected is unknown. If one of the send in a batch update fails to execute properly, this method throws aBatchUpdateException, and a JDBC driver may or may not continue to process the remaining send in the batch. However, the driver's behavior must be consistent with a particular DBMS, either always continuing to process send or never continuing to process send. If the driver continues processing after a failure, the array returned by the methodBatchUpdateException.getUpdateCountswill contain as many elements as there are send in the batch, and at least one of the elements will be the following: - A value of
EXECUTE_FAILED-- indicates that the command failed to execute successfully and occurs only if a driver continues to process send after a command fails
The possible implementations and return values have been modified in the Java 2 SDK, Standard Edition, version 1.3 to accommodate the option of continuing to proccess send in a batch update after a
BatchUpdateExceptionobject has been thrown.- Specified by:
executeBatchin interfaceStatement- Overrides:
executeBatchin classMariaDbStatement- Returns:
- an array of update counts containing one element for each command in the batch. The elements of the array are ordered according to the order in which send were added to the batch.
- Throws:
SQLException- if a database access error occurs, this method is called on a closedStatementor the driver does not support batch statements. ThrowsBatchUpdateException(a subclass ofSQLException) if one of the send sent to the database fails to execute properly or attempts to return a result set.- Since:
- 1.3
- See Also:
-
executeLargeBatch
Execute batch, like executeBatch(), with returning results with long[]. For when row count may exceed Integer.MAX_VALUE.- Specified by:
executeLargeBatchin interfaceStatement- Overrides:
executeLargeBatchin classMariaDbStatement- Returns:
- an array of update counts (one element for each command in the batch)
- Throws:
SQLException- if a database error occur.
-
executeBatchInternal
- Throws:
SQLException
-
executeQueryPrologue
- Throws:
SQLException
-
executeQuery
- Specified by:
executeQueryin interfacePreparedStatement- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdatein interfacePreparedStatement- Throws:
SQLException
-
clearParameters
public void clearParameters()- Specified by:
clearParametersin interfacePreparedStatement
-
execute
- Specified by:
executein interfacePreparedStatement- Throws:
SQLException
-
validParameters
- Throws:
SQLException
-
executeInternal
- Specified by:
executeInternalin classBasePrepareStatement- Throws:
SQLException
-
close
Releases this
Statementobject's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed. It is generally good practice to release resources as soon as you are finished with them to avoid tying up database resources.Calling the method
closeon aStatementobject that is already closed has no effect.Note:When a
Statementobject is closed, its currentResultSetobject, if one exists, is also closed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceStatement- Overrides:
closein classMariaDbStatement- Throws:
SQLException- if a database access error occurs
-
getParameterCount
protected int getParameterCount() -
toString
Return sql String value. -
getServerThreadId
public long getServerThreadId()Permit to retrieve current connection thread id, or -1 if unknown.- Overrides:
getServerThreadIdin classMariaDbStatement- Returns:
- current connection thread id.
-