Class ServerPreparedStatement
- java.lang.Object
-
- org.mariadb.jdbc.Statement
-
- org.mariadb.jdbc.BasePreparedStatement
-
- org.mariadb.jdbc.ServerPreparedStatement
-
- All Implemented Interfaces:
AutoCloseable,PreparedStatement,Statement,Wrapper
- Direct Known Subclasses:
BaseCallableStatement
public class ServerPreparedStatement extends BasePreparedStatement
-
-
Field Summary
-
Fields inherited from class org.mariadb.jdbc.BasePreparedStatement
batchParameters, parameters, prepareResult, sql
-
Fields inherited from class org.mariadb.jdbc.Statement
autoGeneratedKeys, canUseServerMaxRows, canUseServerTimeout, closed, closeOnCompletion, con, currResult, escape, fetchSize, lock, maxRows, queryTimeout, results, resultSetConcurrency, resultSetType
-
Fields 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
Constructors Constructor Description ServerPreparedStatement(String sql, Connection con, ReentrantLock lock, boolean canUseServerTimeout, boolean canUseServerMaxRows, int autoGeneratedKeys, int resultSetType, int resultSetConcurrency, int defaultFetchSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBatch()Adds a set of parameters to thisPreparedStatementobject's batch of commands.voidclose()Releases thisStatementobject's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed.booleanexecute()Executes the SQL statement in thisPreparedStatementobject, which may be any kind of SQL statement.int[]executeBatch()Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts.protected voidexecuteInternal()long[]executeLargeBatch()Execute batch, like executeBatch(), with returning results with long[].longexecuteLargeUpdate()Executes the SQL statement in thisPreparedStatementobject, which must be an SQL Data Manipulation Language (DML) statement, such asINSERT,UPDATEorDELETE; or an SQL statement that returns nothing, such as a DDL statement.ResultSetexecuteQuery()Executes the SQL query in thisPreparedStatementobject and returns theResultSetobject generated by the query.intexecuteUpdate()Executes the SQL statement in thisPreparedStatementobject, which must be an SQL Data Manipulation Language (DML) statement, such asINSERT,UPDATEorDELETE; or an SQL statement that returns nothing, such as a DDL statement.ResultSetMetaDatagetMetaData()Retrieves aResultSetMetaDataobject that contains information about the columns of theResultSetobject that will be returned when thisPreparedStatementobject is executed.ParameterMetaDatagetParameterMetaData()Retrieves the number, types and properties of thisPreparedStatementobject's parameters.protected voidhandleParameterOutput()voidreset()voidsetLargeMaxRows(long max)Sets the limit for the maximum number of rows that any ResultSet object generated by this Statement object can contain to the given number.voidsetMaxRows(int max)Sets the limit for the maximum number of rows that anyResultSetobject generated by thisStatementobject can contain to the given number.voidsetQueryTimeout(int seconds)Sets the number of seconds the driver will wait for aStatementobject to execute to the given number of seconds.protected voidvalidParameters()-
Methods inherited from class org.mariadb.jdbc.BasePreparedStatement
addBatch, clearParameters, execute, execute, execute, execute, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeQuery, executeUpdate, executeUpdate, executeUpdate, executeUpdate, getMeta, 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, setObject, setObject, setObject, setObject, setObject, setParameter, setParameters, setPrepareResult, setRef, setRowId, setShort, setSQLXML, setString, setTime, setTime, setTimestamp, setTimestamp, setUnicodeStream, setURL, updateMeta
-
Methods inherited from class org.mariadb.jdbc.Statement
abort, cancel, checkNotClosed, clearBatch, clearWarnings, closeOnCompletion, escapeTimeout, exceptionFactory, executeInternalBatchPipeline, executeInternalBatchStandard, fetchRemaining, 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, setMaxFieldSize, setPoolable, unwrap
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.sql.Statement
cancel, clearBatch, clearWarnings, closeOnCompletion, enquoteIdentifier, enquoteLiteral, enquoteNCharLiteral, 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, setMaxFieldSize, setPoolable
-
Methods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
-
-
-
-
Constructor Detail
-
ServerPreparedStatement
public ServerPreparedStatement(String sql, Connection con, ReentrantLock lock, boolean canUseServerTimeout, boolean canUseServerMaxRows, int autoGeneratedKeys, int resultSetType, int resultSetConcurrency, int defaultFetchSize) throws SQLException
- Throws:
SQLException
-
-
Method Detail
-
executeInternal
protected void executeInternal() throws SQLException- Throws:
SQLException
-
execute
public boolean execute() throws SQLExceptionExecutes the SQL statement in thisPreparedStatementobject, which may be any kind of SQL statement. Some prepared statements return multiple results; theexecutemethod handles these complex statements as well as the simpler form of statements handled by the methodsexecuteQueryandexecuteUpdate.The
executemethod returns abooleanto indicate the form of the first result. You must call either the methodgetResultSetorgetUpdateCountto retrieve the result; you must callgetMoreResultsto move to any subsequent result(s).- Specified by:
executein interfacePreparedStatement- Specified by:
executein classBasePreparedStatement- Returns:
trueif the first result is aResultSetobject;falseif the first result is an update count or there is no result- Throws:
SQLException- if a database access error occurs; this method is called on a closedPreparedStatementor an argument is supplied to this methodSQLTimeoutException- when the driver has determined that the timeout value that was specified by thesetQueryTimeoutmethod has been exceeded and has at least attempted to cancel the currently runningStatement- See Also:
Statement.execute(java.lang.String),Statement.getResultSet(),Statement.getUpdateCount(),Statement.getMoreResults()
-
setMaxRows
public void setMaxRows(int max) throws SQLExceptionDescription copied from class:StatementSets the limit for the maximum number of rows that anyResultSetobject generated by thisStatementobject can contain to the given number. If the limit is exceeded, the excess rows are silently dropped.- Specified by:
setMaxRowsin interfaceStatement- Overrides:
setMaxRowsin classStatement- Parameters:
max- the new max rows limit; zero means there is no limit- Throws:
SQLException- if a database access error occurs, this method is called on a closedStatementor the conditionmax >= 0is not satisfied- See Also:
Statement.getMaxRows()
-
setLargeMaxRows
public void setLargeMaxRows(long max) throws SQLExceptionDescription copied from class:StatementSets the limit for the maximum number of rows that any ResultSet object generated by this Statement object can contain to the given number. If the limit is exceeded, the excess rows are silently dropped.- Specified by:
setLargeMaxRowsin interfaceStatement- Overrides:
setLargeMaxRowsin classStatement- Parameters:
max- the new max rows limit; zero means there is no limit- Throws:
SQLException- if the condition max >= 0 is not satisfied
-
setQueryTimeout
public void setQueryTimeout(int seconds) throws SQLExceptionDescription copied from class:StatementSets the number of seconds the driver will wait for aStatementobject to execute to the given number of seconds. By default, there is no limit on the amount of time allowed for a running statement to complete. If the limit is exceeded, anSQLTimeoutExceptionis thrown. A JDBC driver must apply this limit to theexecute,executeQueryandexecuteUpdatemethods.Note: JDBC driver implementations may also apply this limit to
ResultSetmethods (consult your driver vendor documentation for details).Note: In the case of
Statementbatching, it is implementation defined whether the time-out is applied to individual SQL commands added via theaddBatchmethod or to the entire batch of SQL commands invoked by theexecuteBatchmethod (consult your driver vendor documentation for details).- Specified by:
setQueryTimeoutin interfaceStatement- Overrides:
setQueryTimeoutin classStatement- Parameters:
seconds- the new query timeout limit in seconds; zero means there is no limit- Throws:
SQLException- if a database access error occurs, this method is called on a closedStatementor the conditionseconds >= 0is not satisfied- See Also:
Statement.getQueryTimeout()
-
executeQuery
public ResultSet executeQuery() throws SQLException
Executes the SQL query in thisPreparedStatementobject and returns theResultSetobject generated by the query.- Specified by:
executeQueryin interfacePreparedStatement- Specified by:
executeQueryin classBasePreparedStatement- Returns:
- a
ResultSetobject that contains the data produced by the query; nevernull - Throws:
SQLException- if a database access error occurs; this method is called on a closedPreparedStatementor the SQL statement does not return aResultSetobjectSQLTimeoutException- when the driver has determined that the timeout value that was specified by thesetQueryTimeoutmethod has been exceeded and has at least attempted to cancel the currently runningStatement
-
executeUpdate
public int executeUpdate() throws SQLExceptionExecutes the SQL statement in thisPreparedStatementobject, which must be an SQL Data Manipulation Language (DML) statement, such asINSERT,UPDATEorDELETE; or an SQL statement that returns nothing, such as a DDL statement.- Specified by:
executeUpdatein interfacePreparedStatement- Specified by:
executeUpdatein classBasePreparedStatement- Returns:
- either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
- Throws:
SQLException- if a database access error occurs; this method is called on a closedPreparedStatementor the SQL statement returns aResultSetobjectSQLTimeoutException- when the driver has determined that the timeout value that was specified by thesetQueryTimeoutmethod has been exceeded and has at least attempted to cancel the currently runningStatement
-
executeLargeUpdate
public long executeLargeUpdate() throws SQLExceptionExecutes the SQL statement in thisPreparedStatementobject, which must be an SQL Data Manipulation Language (DML) statement, such asINSERT,UPDATEorDELETE; or an SQL statement that returns nothing, such as a DDL statement.This method should be used when the returned row count may exceed
Integer.MAX_VALUE.The default implementation will throw
UnsupportedOperationException- Specified by:
executeLargeUpdatein interfacePreparedStatement- Specified by:
executeLargeUpdatein classBasePreparedStatement- Returns:
- either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
- Throws:
SQLException- if a database access error occurs; this method is called on a closedPreparedStatementor the SQL statement returns aResultSetobjectSQLTimeoutException- when the driver has determined that the timeout value that was specified by thesetQueryTimeoutmethod has been exceeded and has at least attempted to cancel the currently runningStatement- Since:
- 1.8
-
handleParameterOutput
protected void handleParameterOutput() throws SQLException- Throws:
SQLException
-
addBatch
public void addBatch() throws SQLExceptionAdds a set of parameters to thisPreparedStatementobject's batch of commands.- Specified by:
addBatchin interfacePreparedStatement- Specified by:
addBatchin classBasePreparedStatement- Throws:
SQLException- if a database access error occurs or this method is called on a closedPreparedStatement- Since:
- 1.2
- See Also:
Statement.addBatch(java.lang.String)
-
validParameters
protected void validParameters() throws SQLException- Throws:
SQLException
-
getMetaData
public ResultSetMetaData getMetaData() throws SQLException
Retrieves aResultSetMetaDataobject that contains information about the columns of theResultSetobject that will be returned when thisPreparedStatementobject is executed.Because a
PreparedStatementobject is precompiled, it is possible to know about theResultSetobject that it will return without having to execute it. Consequently, it is possible to invoke the methodgetMetaDataon aPreparedStatementobject rather than waiting to execute it and then invoking theResultSet.getMetaDatamethod on theResultSetobject that is returned.NOTE: Using this method may be expensive for some drivers due to the lack of underlying DBMS support.
- Specified by:
getMetaDatain interfacePreparedStatement- Specified by:
getMetaDatain classBasePreparedStatement- Returns:
- the description of a
ResultSetobject's columns ornullif the driver cannot return aResultSetMetaDataobject - Throws:
SQLException- if a database access error occurs or this method is called on a closedPreparedStatementSQLFeatureNotSupportedException- if the JDBC driver does not support this method- Since:
- 1.2
-
getParameterMetaData
public ParameterMetaData getParameterMetaData() throws SQLException
Retrieves the number, types and properties of thisPreparedStatementobject's parameters.- Specified by:
getParameterMetaDatain interfacePreparedStatement- Specified by:
getParameterMetaDatain classBasePreparedStatement- 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- Since:
- 1.4
- See Also:
ParameterMetaData
-
executeBatch
public int[] executeBatch() throws SQLExceptionDescription copied from class:StatementSubmits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts. Theintelements of the array that is returned are ordered to correspond to the commands 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 unknownIf one of the commands in a batch update fails to execute properly, this method throws a
BatchUpdateException, and a JDBC driver may or may not continue to process the remaining commands in the batch. However, the driver's behavior must be consistent with a particular DBMS, either always continuing to process commands or never continuing to process commands. If the driver continues processing after a failure, the array returned by the methodBatchUpdateException.getUpdateCountswill contain as many elements as there are commands 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 commands 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 process commands in a batch update after a
BatchUpdateExceptionobject has been thrown.- Specified by:
executeBatchin interfaceStatement- Specified by:
executeBatchin classBasePreparedStatement- 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 commands 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 commands sent to the database fails to execute properly or attempts to return a result set.SQLTimeoutException- when the driver has determined that the timeout value that was specified by thesetQueryTimeoutmethod has been exceeded and has at least attempted to cancel the currently runningStatement- See Also:
Statement.addBatch(java.lang.String),DatabaseMetaData.supportsBatchUpdates()
-
executeLargeBatch
public long[] executeLargeBatch() throws SQLExceptionDescription copied from class:StatementExecute batch, like executeBatch(), with returning results with long[]. For when row count may exceed Integer.MAX_VALUE.- Specified by:
executeLargeBatchin interfaceStatement- Specified by:
executeLargeBatchin classBasePreparedStatement- Returns:
- an array of update counts (one element for each command in the batch)
- Throws:
SQLException- if a database error occur.
-
close
public void close() throws SQLExceptionDescription copied from class:StatementReleases thisStatementobject'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 classStatement- Throws:
SQLException- if a database access error occurs
-
reset
public void reset()
-
-