Class ServerPreparedStatement
- All Implemented Interfaces:
AutoCloseable
,PreparedStatement
,Statement
,Wrapper
- Direct Known Subclasses:
BaseCallableStatement
-
Field Summary
FieldsFields inherited from class org.mariadb.jdbc.BasePreparedStatement
batchParameters, parameters, prepareResult, sql
Fields inherited from class org.mariadb.jdbc.Statement
autoGeneratedKeys, clientParser, closed, closeOnCompletion, con, currResult, escape, fetchSize, lastSql, localInfileInputStream, 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
ConstructorsConstructorDescriptionServerPreparedStatement
(String sql, Connection con, ClosableLock lock, int autoGeneratedKeys, int resultSetType, int resultSetConcurrency, int defaultFetchSize) Server prepare statement constructor -
Method Summary
Modifier and TypeMethodDescriptionvoid
addBatch()
Adds a set of parameters to thisPreparedStatement
object's batch of commands.void
close()
Releases thisStatement
object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed.protected ExceptionFactory
boolean
execute()
Executes the SQL statement in thisPreparedStatement
object, which may be any kind of SQL statement.private void
Send COM_STMT_PREPARE + X * COM_STMT_EXECUTE, then read for the all answersprivate void
Send COM_STMT_PREPARE + read answer, then Send a COM_STMT_EXECUTE + read answer * n timeprivate List
<Completion> executeBunch
(String cmd, int index, int maxCmd) private List
<Completion> executeBunchPrepare
(String cmd, int index, int maxCmd) protected void
Execute command with parametersprotected boolean
long
Executes the SQL statement in thisPreparedStatement
object, which must be an SQL Data Manipulation Language (DML) statement, such asINSERT
,UPDATE
orDELETE
; or an SQL statement that returns nothing, such as a DDL statement.private void
executePipeline
(String cmd) Send COM_STMT_PREPARE + COM_STMT_EXECUTE, then read for the 2 answersExecutes the SQL query in thisPreparedStatement
object and returns theResultSet
object generated by the query.private void
executeStandard
(String cmd) int
Executes the SQL statement in thisPreparedStatement
object, which must be an SQL Data Manipulation Language (DML) statement, such asINSERT
,UPDATE
orDELETE
; or an SQL statement that returns nothing, such as a DDL statement.Retrieves aResultSetMetaData
object that contains information about the columns of theResultSet
object that will be returned when thisPreparedStatement
object is executed.Retrieves the number, types and properties of thisPreparedStatement
object's parameters.protected void
Handle output parameter result-set (only for CallableStatement)void
setLargeMaxRows
(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.void
setMaxRows
(int max) Sets the limit for the maximum number of rows that anyResultSet
object generated by thisStatement
object can contain to the given number.void
setQueryTimeout
(int seconds) Sets the number of seconds the driver will wait for aStatement
object to execute to the given number of seconds.toString()
protected void
Validated that all parameters have been set.Methods inherited from class org.mariadb.jdbc.BasePreparedStatement
addBatch, clearBatch, clearParameters, execute, execute, execute, execute, executeBatch, executeBatchBulk, executeLargeBatch, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeQuery, executeUpdate, executeUpdate, executeUpdate, executeUpdate, getGeneratedKeys, getLastSql, getMeta, reset, 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, setPrepareResult, setRef, setRowId, setShort, setSQLXML, setString, setTime, setTime, setTimestamp, setTimestamp, setUnicodeStream, setURL, updateMeta
Methods inherited from class org.mariadb.jdbc.Statement
abort, cancel, checkNotClosed, clearWarnings, closeOnCompletion, enquoteIdentifier, enquoteLiteral, enquoteNCharLiteral, escapeTimeout, fetchRemaining, getConnection, getFetchDirection, getFetchSize, getLargeMaxRows, getLargeUpdateCount, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, isClosed, isCloseOnCompletion, isPoolable, isWrapperFor, parseCommandIfNeeded, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setLocalInfileInputStream, setMaxFieldSize, setPoolable, unwrap
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.sql.Statement
cancel, clearWarnings, closeOnCompletion, enquoteIdentifier, enquoteLiteral, enquoteNCharLiteral, getConnection, getFetchDirection, getFetchSize, 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
-
Field Details
-
PREPARABLE_STATEMENT_PATTERN
-
-
Constructor Details
-
ServerPreparedStatement
public ServerPreparedStatement(String sql, Connection con, ClosableLock lock, int autoGeneratedKeys, int resultSetType, int resultSetConcurrency, int defaultFetchSize) throws SQLException Server prepare statement constructor- Parameters:
sql
- commandcon
- connectionlock
- thread safe lockautoGeneratedKeys
- must command return automatically generated keysresultSetType
- resultset typeresultSetConcurrency
- resultset concurrencydefaultFetchSize
- default fetch size- Throws:
SQLException
- if prepare fails
-
-
Method Details
-
executeInternal
Execute command with parameters- Throws:
SQLException
- if any error occurs
-
executePipeline
Send COM_STMT_PREPARE + COM_STMT_EXECUTE, then read for the 2 answers- Parameters:
cmd
- command- Throws:
SQLException
- if IOException / Command error
-
executeStandard
- Throws:
SQLException
-
executeInternalPreparedBatch
- Specified by:
executeInternalPreparedBatch
in classBasePreparedStatement
- Throws:
SQLException
-
executeBatchPipeline
Send COM_STMT_PREPARE + X * COM_STMT_EXECUTE, then read for the all answers- Parameters:
cmd
- command- Throws:
SQLException
- if Command error
-
executeBunch
- Throws:
SQLException
-
executeBunchPrepare
- Throws:
SQLException
-
executeBatchStandard
Send COM_STMT_PREPARE + read answer, then Send a COM_STMT_EXECUTE + read answer * n time- Parameters:
cmd
- command- Throws:
SQLException
- if IOException / Command error
-
execute
Executes the SQL statement in thisPreparedStatement
object, which may be any kind of SQL statement. Some prepared statements return multiple results; theexecute
method handles these complex statements as well as the simpler form of statements handled by the methodsexecuteQuery
andexecuteUpdate
.The
execute
method returns aboolean
to indicate the form of the first result. You must call either the methodgetResultSet
orgetUpdateCount
to retrieve the result; you must callgetMoreResults
to move to any subsequent result(s).- Specified by:
execute
in interfacePreparedStatement
- Specified by:
execute
in classBasePreparedStatement
- Returns:
true
if the first result is aResultSet
object;false
if 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 closedPreparedStatement
or an argument is supplied to this methodSQLTimeoutException
- when the driver has determined that the timeout value that was specified by thesetQueryTimeout
method has been exceeded and has at least attempted to cancel the currently runningStatement
- See Also:
-
setMaxRows
Description copied from class:Statement
Sets the limit for the maximum number of rows that anyResultSet
object generated by thisStatement
object can contain to the given number. If the limit is exceeded, the excess rows are silently dropped.- Specified by:
setMaxRows
in interfaceStatement
- Overrides:
setMaxRows
in 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 closedStatement
or the conditionmax >= 0
is not satisfied- See Also:
-
setLargeMaxRows
Description copied from class:Statement
Sets 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:
setLargeMaxRows
in interfaceStatement
- Overrides:
setLargeMaxRows
in 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
Description copied from class:Statement
Sets the number of seconds the driver will wait for aStatement
object 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, anSQLTimeoutException
is thrown. A JDBC driver must apply this limit to theexecute
,executeQuery
andexecuteUpdate
methods.Note: JDBC driver implementations may also apply this limit to
ResultSet
methods (consult your driver vendor documentation for details).Note: In the case of
Statement
batching, it is implementation defined whether the time-out is applied to individual SQL commands added via theaddBatch
method or to the entire batch of SQL commands invoked by theexecuteBatch
method (consult your driver vendor documentation for details).- Specified by:
setQueryTimeout
in interfaceStatement
- Overrides:
setQueryTimeout
in 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 closedStatement
or the conditionseconds >= 0
is not satisfied- See Also:
-
executeQuery
Executes the SQL query in thisPreparedStatement
object and returns theResultSet
object generated by the query.- Specified by:
executeQuery
in interfacePreparedStatement
- Specified by:
executeQuery
in classBasePreparedStatement
- Returns:
- a
ResultSet
object that contains the data produced by the query; nevernull
- Throws:
SQLException
- if a database access error occurs; this method is called on a closedPreparedStatement
or the SQL statement does not return aResultSet
objectSQLTimeoutException
- when the driver has determined that the timeout value that was specified by thesetQueryTimeout
method has been exceeded and has at least attempted to cancel the currently runningStatement
-
executeUpdate
Executes the SQL statement in thisPreparedStatement
object, which must be an SQL Data Manipulation Language (DML) statement, such asINSERT
,UPDATE
orDELETE
; or an SQL statement that returns nothing, such as a DDL statement.- Specified by:
executeUpdate
in interfacePreparedStatement
- Specified by:
executeUpdate
in 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 closedPreparedStatement
or the SQL statement returns aResultSet
objectSQLTimeoutException
- when the driver has determined that the timeout value that was specified by thesetQueryTimeout
method has been exceeded and has at least attempted to cancel the currently runningStatement
-
executeLargeUpdate
Executes the SQL statement in thisPreparedStatement
object, which must be an SQL Data Manipulation Language (DML) statement, such asINSERT
,UPDATE
orDELETE
; 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:
executeLargeUpdate
in interfacePreparedStatement
- Specified by:
executeLargeUpdate
in 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 closedPreparedStatement
or the SQL statement returns aResultSet
objectSQLTimeoutException
- when the driver has determined that the timeout value that was specified by thesetQueryTimeout
method has been exceeded and has at least attempted to cancel the currently runningStatement
- Since:
- 1.8
-
handleParameterOutput
Handle output parameter result-set (only for CallableStatement)- Throws:
SQLException
- if any error occurs
-
addBatch
Adds a set of parameters to thisPreparedStatement
object's batch of commands.- Specified by:
addBatch
in interfacePreparedStatement
- Specified by:
addBatch
in classBasePreparedStatement
- Throws:
SQLException
- if a database access error occurs or this method is called on a closedPreparedStatement
- Since:
- 1.2
- See Also:
-
validParameters
Validated that all parameters have been set.- Throws:
SQLException
- if number of parameters doesn't correspond to expected number
-
getMetaData
Retrieves aResultSetMetaData
object that contains information about the columns of theResultSet
object that will be returned when thisPreparedStatement
object is executed.Because a
PreparedStatement
object is precompiled, it is possible to know about theResultSet
object that it will return without having to execute it. Consequently, it is possible to invoke the methodgetMetaData
on aPreparedStatement
object rather than waiting to execute it and then invoking theResultSet.getMetaData
method on theResultSet
object that is returned.NOTE: Using this method may be expensive for some drivers due to the lack of underlying DBMS support.
- Specified by:
getMetaData
in interfacePreparedStatement
- Specified by:
getMetaData
in classBasePreparedStatement
- Returns:
- the description of a
ResultSet
object's columns ornull
if the driver cannot return aResultSetMetaData
object - Throws:
SQLException
- if a database access error occurs or this method is called on a closedPreparedStatement
SQLFeatureNotSupportedException
- if the JDBC driver does not support this method- Since:
- 1.2
-
getParameterMetaData
Retrieves the number, types and properties of thisPreparedStatement
object's parameters.- Specified by:
getParameterMetaData
in interfacePreparedStatement
- Specified by:
getParameterMetaData
in classBasePreparedStatement
- Returns:
- a
ParameterMetaData
object that contains information about the number, types and properties for each parameter marker of thisPreparedStatement
object - Throws:
SQLException
- if a database access error occurs or this method is called on a closedPreparedStatement
- Since:
- 1.4
- See Also:
-
exceptionFactory
-
close
Description copied from class:Statement
Releases thisStatement
object'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
close
on aStatement
object that is already closed has no effect.Note:When a
Statement
object is closed, its currentResultSet
object, if one exists, is also closed.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceStatement
- Overrides:
close
in classStatement
- Throws:
SQLException
- if a database access error occurs
-
toString
- Overrides:
toString
in classBasePreparedStatement
-