Class ClientPreparedStatement
- java.lang.Object
-
- org.mariadb.jdbc.Statement
-
- org.mariadb.jdbc.BasePreparedStatement
-
- org.mariadb.jdbc.ClientPreparedStatement
-
- All Implemented Interfaces:
java.lang.AutoCloseable,java.sql.PreparedStatement,java.sql.Statement,java.sql.Wrapper
public class ClientPreparedStatement extends BasePreparedStatement
Client side prepare statement. Question mark will be replaced by escaped parameters, client side
-
-
Field Summary
Fields Modifier and Type Field Description private ClientParserparser-
Fields inherited from class org.mariadb.jdbc.BasePreparedStatement
batchParameters, canCachePrepStmts, parameters, prepareResult, sql
-
Fields inherited from class org.mariadb.jdbc.Statement
autoGeneratedKeys, canUseServerMaxRows, canUseServerTimeout, clientParser, closed, closeOnCompletion, con, currResult, escape, fetchSize, lastSql, localInfileInputStream, lock, maxRows, queryTimeout, results, resultSetConcurrency, resultSetType
-
-
Constructor Summary
Constructors Constructor Description ClientPreparedStatement(java.lang.String sql, Connection con, ClosableLock lock, boolean canUseServerTimeout, boolean canUseServerMaxRows, int autoGeneratedKeys, int resultSetType, int resultSetConcurrency, int defaultFetchSize)Client prepare statement constructor
-
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.private ExceptionFactoryexceptionFactory()booleanexecute()Executes the SQL statement in thisPreparedStatementobject, which may be any kind of SQL statement.private voidexecuteBatchPipeline()Send n * COM_QUERY + n * read answerprivate voidexecuteBatchStd()Send n * (COM_QUERY + read answer)private voidexecuteInternal()protected booleanexecuteInternalPreparedBatch()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.java.sql.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.java.sql.ResultSetMetaDatagetMetaData()Retrieves aResultSetMetaDataobject that contains information about the columns of theResultSetobject that will be returned when thisPreparedStatementobject is executed.java.sql.ParameterMetaDatagetParameterMetaData()Retrieves the number, types and properties of thisPreparedStatementobject's parameters.protected java.lang.StringpreSqlCmd()use additional part for timeout if possiblevoidsetLargeMaxRows(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.java.lang.StringtoString()protected voidvalidParameters()Validate parameter number according to expected parameter.-
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, executeInternalBatchPipeline, executeInternalBatchStandard, fetchRemaining, getConnection, getFetchDirection, getFetchSize, getLargeMaxRows, getLargeUpdateCount, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, isClosed, isCloseOnCompletion, isPoolable, isSimpleIdentifier, 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, getConnection, getFetchDirection, getFetchSize, getLargeMaxRows, getLargeUpdateCount, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, isClosed, isCloseOnCompletion, isPoolable, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setMaxFieldSize, setPoolable
-
-
-
-
Field Detail
-
parser
private final ClientParser parser
-
-
Constructor Detail
-
ClientPreparedStatement
public ClientPreparedStatement(java.lang.String sql, Connection con, ClosableLock lock, boolean canUseServerTimeout, boolean canUseServerMaxRows, int autoGeneratedKeys, int resultSetType, int resultSetConcurrency, int defaultFetchSize)Client prepare statement constructor- Parameters:
sql- commandcon- connectionlock- thread safe lockcanUseServerTimeout- can server use timeoutcanUseServerMaxRows- can server use max rowsautoGeneratedKeys- must command return automatically generated keysresultSetType- resultset typeresultSetConcurrency- resultset concurrencydefaultFetchSize- default fetch size
-
-
Method Detail
-
preSqlCmd
protected java.lang.String preSqlCmd()
use additional part for timeout if possible- Returns:
- pre command for handling timeout
-
executeInternal
private void executeInternal() throws java.sql.SQLException- Throws:
java.sql.SQLException
-
executeInternalPreparedBatch
protected boolean executeInternalPreparedBatch() throws java.sql.SQLException- Specified by:
executeInternalPreparedBatchin classBasePreparedStatement- Throws:
java.sql.SQLException
-
executeBatchPipeline
private void executeBatchPipeline() throws java.sql.SQLExceptionSend n * COM_QUERY + n * read answer- Throws:
java.sql.SQLException- if IOException / Command error
-
executeBatchStd
private void executeBatchStd() throws java.sql.SQLExceptionSend n * (COM_QUERY + read answer)- Throws:
java.sql.SQLException- if IOException / Command error
-
execute
public boolean execute() throws java.sql.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 interfacejava.sql.PreparedStatement- 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:
java.sql.SQLException- if a database access error occurs; this method is called on a closedPreparedStatementor an argument is supplied to this methodjava.sql.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.execute(java.lang.String),Statement.getResultSet(),Statement.getUpdateCount(),Statement.getMoreResults()
-
executeQuery
public java.sql.ResultSet executeQuery() throws java.sql.SQLExceptionExecutes the SQL query in thisPreparedStatementobject and returns theResultSetobject generated by the query.- Specified by:
executeQueryin interfacejava.sql.PreparedStatement- Specified by:
executeQueryin classBasePreparedStatement- Returns:
- a
ResultSetobject that contains the data produced by the query; nevernull - Throws:
java.sql.SQLException- if a database access error occurs; this method is called on a closedPreparedStatementor the SQL statement does not return aResultSetobjectjava.sql.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
-
executeUpdate
public int executeUpdate() throws java.sql.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 interfacejava.sql.PreparedStatement- 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:
java.sql.SQLException- if a database access error occurs; this method is called on a closedPreparedStatementor the SQL statement returns aResultSetobjectjava.sql.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
-
executeLargeUpdate
public long executeLargeUpdate() throws java.sql.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 interfacejava.sql.PreparedStatement- 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:
java.sql.SQLException- if a database access error occurs; this method is called on a closedPreparedStatementor the SQL statement returns aResultSetobjectjava.sql.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- Since:
- 1.8
-
exceptionFactory
private ExceptionFactory exceptionFactory()
-
addBatch
public void addBatch() throws java.sql.SQLExceptionAdds a set of parameters to thisPreparedStatementobject's batch of commands.- Specified by:
addBatchin interfacejava.sql.PreparedStatement- Specified by:
addBatchin classBasePreparedStatement- Throws:
java.sql.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 java.sql.SQLExceptionValidate parameter number according to expected parameter.- Throws:
java.sql.SQLException- if doesn't correspond
-
setQueryTimeout
public void setQueryTimeout(int seconds) throws java.sql.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 interfacejava.sql.Statement- Overrides:
setQueryTimeoutin classStatement- Parameters:
seconds- the new query timeout limit in seconds; zero means there is no limit- Throws:
java.sql.SQLException- if a database access error occurs, this method is called on a closedStatementor the conditionseconds >= 0is not satisfied- See Also:
Statement.getQueryTimeout()
-
setMaxRows
public void setMaxRows(int max) throws java.sql.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 interfacejava.sql.Statement- Overrides:
setMaxRowsin classStatement- Parameters:
max- the new max rows limit; zero means there is no limit- Throws:
java.sql.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 java.sql.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 interfacejava.sql.Statement- Overrides:
setLargeMaxRowsin classStatement- Parameters:
max- the new max rows limit; zero means there is no limit- Throws:
java.sql.SQLException- if the condition max >= 0 is not satisfied
-
getMetaData
public java.sql.ResultSetMetaData getMetaData() throws java.sql.SQLExceptionRetrieves 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.- Specified by:
getMetaDatain interfacejava.sql.PreparedStatement- Specified by:
getMetaDatain classBasePreparedStatement- Returns:
- the description of a
ResultSetobject's columns ornullif the driver cannot return aResultSetMetaDataobject - Throws:
java.sql.SQLException- if a database access error occurs or this method is called on a closedPreparedStatement
-
getParameterMetaData
public java.sql.ParameterMetaData getParameterMetaData() throws java.sql.SQLExceptionRetrieves the number, types and properties of thisPreparedStatementobject's parameters.- Specified by:
getParameterMetaDatain interfacejava.sql.PreparedStatement- Specified by:
getParameterMetaDatain classBasePreparedStatement- Returns:
- a
ParameterMetaDataobject that contains information about the number, types and properties for each parameter marker of thisPreparedStatementobject - Throws:
java.sql.SQLException- if a database access error occurs or this method is called on a closedPreparedStatement- Since:
- 1.4
- See Also:
ParameterMetaData
-
close
public void close() throws java.sql.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.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classBasePreparedStatement
-
-