Class ClientPreparedStatement
- All Implemented Interfaces:
AutoCloseable,PreparedStatement,Statement,Wrapper
-
Field Summary
Fields inherited from class org.mariadb.jdbc.BasePreparedStatement
batchParameters, parameters, prepareResult, sqlFields inherited from class org.mariadb.jdbc.Statement
autoGeneratedKeys, clientParser, closed, closeOnCompletion, con, currResult, escape, fetchSize, lastSql, localInfileInputStream, lock, maxRows, queryTimeout, results, resultSetConcurrency, resultSetTypeFields 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
ConstructorsConstructorDescriptionClientPreparedStatement(String sql, Connection con, ClosableLock lock, int autoGeneratedKeys, int resultSetType, int resultSetConcurrency, int defaultFetchSize) Client prepare statement constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBatch()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.protected booleanlongExecutes 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.Executes the SQL query in thisPreparedStatementobject and returns theResultSetobject generated by the query.intExecutes 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.Retrieves aResultSetMetaDataobject that contains information about the columns of theResultSetobject that will be returned when thisPreparedStatementobject is executed.Retrieves the number, types and properties of thisPreparedStatementobject's parameters.protected Stringuse 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.toString()protected voidValidate 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, updateMetaMethods 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, 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, 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, setPoolableMethods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
-
Constructor Details
-
ClientPreparedStatement
public ClientPreparedStatement(String sql, Connection con, ClosableLock lock, int autoGeneratedKeys, int resultSetType, int resultSetConcurrency, int defaultFetchSize) Client prepare statement constructor- Parameters:
sql- commandcon- connectionlock- thread safe lockautoGeneratedKeys- must command return automatically generated keysresultSetType- resultset typeresultSetConcurrency- resultset concurrencydefaultFetchSize- default fetch size
-
-
Method Details
-
preSqlCmd
use additional part for timeout if possible- Returns:
- pre command for handling timeout
-
executeInternalPreparedBatch
- Specified by:
executeInternalPreparedBatchin classBasePreparedStatement- Throws:
SQLException
-
execute
Executes 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:
-
executeQuery
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
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.- 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
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.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
-
addBatch
Adds 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:
-
validParameters
Validate parameter number according to expected parameter.- Throws:
SQLException- if doesn't correspond
-
setQueryTimeout
Description 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:
-
setMaxRows
Description 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:
-
setLargeMaxRows
Description 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
-
getMetaData
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.- 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 closedPreparedStatement
-
getParameterMetaData
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:
-
close
Description 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
-
toString
- Overrides:
toStringin classBasePreparedStatement
-