Package org.mariadb.jdbc

# Class ClientPreparedStatement

java.lang.Object
org.mariadb.jdbc.Statement
org.mariadb.jdbc.BasePreparedStatement
org.mariadb.jdbc.ClientPreparedStatement

All Implemented Interfaces:
  `AutoCloseable`, `PreparedStatement`, `Statement`, `Wrapper`

public class ClientPreparedStatement extends BasePreparedStatement
Client side prepare statement. Question mark will be replaced by escaped parameters, client side

## Field Summary

### 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`

### 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
`ClientPreparedStatement(String sql, Connection con, ClosableLock lock, boolean canUseServerTimeout, boolean canUseServerMaxRows, int autoGeneratedKeys, int resultSetType, int resultSetConcurrency, int defaultFetchSize)`
Client prepare statement constructor

## Method Summary

Modifier and Type
Method
Description
`void`
`addBatch()`
Adds a set of parameters to this `PreparedStatement` object's batch of commands.
`void`
`close()`
Releases this `Statement` object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed.
`boolean`
`execute()`
Executes the SQL statement in this `PreparedStatement` object, which may be any kind of SQL statement.
`protected boolean`
`executeInternalPreparedBatch()`
`long`
`executeLargeUpdate()`
Executes the SQL statement in this `PreparedStatement` object, which must be an SQL Data Manipulation Language (DML) statement, such as `INSERT`, `UPDATE` or `DELETE`; or an SQL statement that returns nothing, such as a DDL statement.
`ResultSet`
`executeQuery()`
Executes the SQL query in this `PreparedStatement` object and returns the `ResultSet` object generated by the query.
`int`
`executeUpdate()`
Executes the SQL statement in this `PreparedStatement` object, which must be an SQL Data Manipulation Language (DML) statement, such as `INSERT`, `UPDATE` or `DELETE`; or an SQL statement that returns nothing, such as a DDL statement.
`ResultSetMetaData`
`getMetaData()`
Retrieves a `ResultSetMetaData` object that contains information about the columns of the `ResultSet` object that will be returned when this `PreparedStatement` object is executed.
`ParameterMetaData`
`getParameterMetaData()`
Retrieves the number, types and properties of this `PreparedStatement` object's parameters.
`protected String`
`preSqlCmd()`
use additional part for timeout if possible
`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 any `ResultSet` object generated by this `Statement` object can contain to the given number.
`void`
`setQueryTimeout(int seconds)`
Sets the number of seconds the driver will wait for a `Statement` object to execute to the given number of seconds.
`String`
`toString()`
`protected void`
`validParameters()`
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, 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`

## Constructor Details

### ClientPreparedStatement

public ClientPreparedStatement(String sql, Connection con, ClosableLock lock, boolean canUseServerTimeout, boolean canUseServerMaxRows, int autoGeneratedKeys, int resultSetType, int resultSetConcurrency, int defaultFetchSize)
Client prepare statement constructor

Parameters:
  `sql` - command
  `con` - connection
  `lock` - thread safe lock
  `canUseServerTimeout` - can server use timeout
  `canUseServerMaxRows` - can server use max rows
  `autoGeneratedKeys` - must command return automatically generated keys
  `resultSetType` - resultset type
  `resultSetConcurrency` - resultset concurrency
  `defaultFetchSize` - default fetch size

## Method Details

### preSqlCmd

protected String preSqlCmd()
use additional part for timeout if possible

Returns:
  pre command for handling timeout

### executeInternalPreparedBatch

protected boolean executeInternalPreparedBatch() throws SQLException

Specified by:
  `executeInternalPreparedBatch` in class `BasePreparedStatement`
Throws:
  `SQLException`

### execute

public boolean execute() throws SQLException
Executes the SQL statement in this `PreparedStatement` object, which may be any kind of SQL statement. Some prepared statements return multiple results; the `execute` method handles these complex statements as well as the simpler form of statements handled by the methods `executeQuery` and `executeUpdate`.

The `execute` method returns a `boolean` to indicate the form of the first result. You must call either the method `getResultSet` or `getUpdateCount` to retrieve the result; you must call `getMoreResults` to move to any subsequent result(s).

Specified by:
  `execute` in interface `PreparedStatement`
Specified by:
  `execute` in class `BasePreparedStatement`
Returns:
  `true` if the first result is a `ResultSet` 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 closed `PreparedStatement` or an argument is supplied to this method
  `SQLTimeoutException` - when the driver has determined that the timeout value that was specified by the `setQueryTimeout` method has been exceeded and has at least attempted to cancel the currently running `Statement`
See Also:
  - `Statement.execute(java.lang.String)`
  - `Statement.getResultSet()`
  - `Statement.getUpdateCount()`
  - `Statement.getMoreResults()`

### executeQuery

public ResultSet executeQuery() throws SQLException
Executes the SQL query in this `PreparedStatement` object and returns the `ResultSet` object generated by the query.

Specified by:
  `executeQuery` in interface `PreparedStatement`
Specified by:
  `executeQuery` in class `BasePreparedStatement`
Returns:
  a `ResultSet` object that contains the data produced by the query; never `null`
Throws:
  `SQLException` - if a database access error occurs; this method is called on a closed `PreparedStatement` or the SQL statement does not return a `ResultSet` object
  `SQLTimeoutException` - when the driver has determined that the timeout value that was specified by the `setQueryTimeout` method has been exceeded and has at least attempted to cancel the currently running `Statement`

### executeUpdate

public int executeUpdate() throws SQLException
Executes the SQL statement in this `PreparedStatement` object, which must be an SQL Data Manipulation Language (DML) statement, such as `INSERT`, `UPDATE` or `DELETE`; or an SQL statement that returns nothing, such as a DDL statement.

Specified by:
  `executeUpdate` in interface `PreparedStatement`
Specified by:
  `executeUpdate` in class `BasePreparedStatement`
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 closed `PreparedStatement` or the SQL statement returns a `ResultSet` object
  `SQLTimeoutException` - when the driver has determined that the timeout value that was specified by the `setQueryTimeout` method has been exceeded and has at least attempted to cancel the currently running `Statement`

### executeLargeUpdate

public long executeLargeUpdate() throws SQLException
Executes the SQL statement in this `PreparedStatement` object, which must be an SQL Data Manipulation Language (DML) statement, such as `INSERT`, `UPDATE` or `DELETE`; 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 interface `PreparedStatement`
Specified by:
  `executeLargeUpdate` in class `BasePreparedStatement`
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 closed `PreparedStatement` or the SQL statement returns a `ResultSet` object
  `SQLTimeoutException` - when the driver has determined that the timeout value that was specified by the `setQueryTimeout` method has been exceeded and has at least attempted to cancel the currently running `Statement`
Since:
  1.8

### addBatch

public void addBatch() throws SQLException
Adds a set of parameters to this `PreparedStatement` object's batch of commands.

Specified by:
  `addBatch` in interface `PreparedStatement`
Specified by:
  `addBatch` in class `BasePreparedStatement`
Throws:
  `SQLException` - if a database access error occurs or this method is called on a closed `PreparedStatement`
Since:
  1.2
See Also:
  - `Statement.addBatch(java.lang.String)`

### validParameters

protected void validParameters() throws SQLException
Validate parameter number according to expected parameter.

Throws:
  `SQLException` - if doesn't correspond

### setQueryTimeout

public void setQueryTimeout(int seconds) throws SQLException
Description copied from class: `Statement`
Sets the number of seconds the driver will wait for a `Statement` 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, an `SQLTimeoutException` is thrown. A JDBC driver must apply this limit to the `execute`, `executeQuery` and `executeUpdate` 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 the `addBatch` method or to the entire batch of SQL commands invoked by the `executeBatch` method (consult your driver vendor documentation for details).

Specified by:
  `setQueryTimeout` in interface `Statement`
Overrides:
  `setQueryTimeout` in class `Statement`
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 closed `Statement` or the condition `seconds >= 0` is not satisfied
See Also:
  - `Statement.getQueryTimeout()`

### setMaxRows

public void setMaxRows(int max) throws SQLException
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:
  `setMaxRows` in interface `Statement`
Overrides:
  `setMaxRows` in class `Statement`
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 closed `Statement` or the condition `max >= 0` is not satisfied
See Also:
  - `Statement.getMaxRows()`

### setLargeMaxRows

public void setLargeMaxRows(long max) throws SQLException
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 interface `Statement`
Overrides:
  `setLargeMaxRows` in class `Statement`
Parameters:
  `max` - the new max rows limit; zero means there is no limit
Throws:
  `SQLException` - if the condition max >= 0 is not satisfied

### getMetaData

public ResultSetMetaData getMetaData() throws SQLException
Retrieves a `ResultSetMetaData` object that contains information about the columns of the `ResultSet` object that will be returned when this `PreparedStatement` object is executed.

Because a `PreparedStatement` object is precompiled, it is possible to know about the `ResultSet` object that it will return without having to execute it. Consequently, it is possible to invoke the method `getMetaData` on a `PreparedStatement` object rather than waiting to execute it and then invoking the `ResultSet.getMetaData` method on the `ResultSet` object that is returned.

Specified by:
  `getMetaData` in interface `PreparedStatement`
Specified by:
  `getMetaData` in class `BasePreparedStatement`
Returns:
  the description of a `ResultSet` object's columns or `null` if the driver cannot return a `ResultSetMetaData` object
Throws:
  `SQLException` - if a database access error occurs or this method is called on a closed `PreparedStatement`

### getParameterMetaData

public ParameterMetaData getParameterMetaData() throws SQLException
Retrieves the number, types and properties of this `PreparedStatement` object's parameters.

Specified by:
  `getParameterMetaData` in interface `PreparedStatement`
Specified by:
  `getParameterMetaData` in class `BasePreparedStatement`
Returns:
  a `ParameterMetaData` object that contains information about the number, types and properties for each parameter marker of this `PreparedStatement` object
Throws:
  `SQLException` - if a database access error occurs or this method is called on a closed `PreparedStatement`
Since:
  1.4
See Also:
  - `ParameterMetaData`

### close

public void close() throws SQLException
Description copied from class: `Statement`
Releases this `Statement` 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 a `Statement` object that is already closed has no effect.

Note:When a `Statement` object is closed, its current `ResultSet` object, if one exists, is also closed.

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Statement`
Overrides:
  `close` in class `Statement`
Throws:
  `SQLException` - if a database access error occurs

### toString

public String toString()

Overrides:
  `toString` in class `BasePreparedStatement`