Package com.microsoft.sqlserver.jdbc

# Class SQLServerStatement

java.lang.Object
com.microsoft.sqlserver.jdbc.SQLServerStatement

All Implemented Interfaces:
  `ISQLServerStatement`, `Serializable`, `AutoCloseable`, `Statement`, `Wrapper`

Direct Known Subclasses:
  `SQLServerPreparedStatement`

public class SQLServerStatement extends Object implements ISQLServerStatement
Provides an implementation of java.sql.Statement JDBC Interface to assist in creating Statements against SQL Server. It also provides a number of base class implementation methods for the JDBC prepared statement and callable Statements. SQLServerStatement's basic role is to execute SQL statements and return update counts and resultset rows to the user application. Documentation for specific public methods that are undocumented can be found under Sun's standard JDBC documentation for class java.sql.Statement. Those methods are part of Sun's standard JDBC documentation and therefore their documentation is not duplicated here.

Implementation Notes

Fetching Result sets

The queries first rowset is available immediately after the executeQuery. The first rs.next() does not make a server round trip. For non server side resultsets the entire result set is in the rowset. For server side result sets the number of rows in the rowset is set with nFetchSize

The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API interfaces javadoc for those details.

See Also:
  - Serialized Form

## Field Summary

Fields
Modifier and Type
Field
Description
`protected SQLServerStatementColumnEncryptionSetting`
`stmtColumnEncriptionSetting`
Column Encryption Override.

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

## Method Summary

Modifier and Type
Method
Description
`void`
`addBatch(String sql)`
`final void`
`cancel()`
`void`
`clearBatch()`
`final void`
`clearWarnings()`
`void`
`close()`
`void`
`closeOnCompletion()`
`boolean`
`execute(String sql)`
`final boolean`
`execute(String sql, int autoGeneratedKeys)`
`final boolean`
`execute(String sql, int[] columnIndexes)`
`final boolean`
`execute(String sql, String[] columnNames)`
`int[]`
`executeBatch()`
Sends a batch of statements to the database.
`long[]`
`executeLargeBatch()`
`long`
`executeLargeUpdate(String sql)`
`final long`
`executeLargeUpdate(String sql, int autoGeneratedKeys)`
`final long`
`executeLargeUpdate(String sql, int[] columnIndexes)`
`final long`
`executeLargeUpdate(String sql, String[] columnNames)`
`ResultSet`
`executeQuery(String sql)`
`int`
`executeUpdate(String sql)`
`final int`
`executeUpdate(String sql, int autoGeneratedKeys)`
`final int`
`executeUpdate(String sql, int[] columnIndexes)`
`final int`
`executeUpdate(String sql, String[] columnNames)`
`final int`
`getCancelQueryTimeout()`
Returns the `cancelQueryTimeout` property set on this SQLServerStatement object.
`final Connection`
`getConnection()`
Returns the statement's connection.
`final int`
`getFetchDirection()`
`final int`
`getFetchSize()`
`final ResultSet`
`getGeneratedKeys()`
`final long`
`getLargeMaxRows()`
`final long`
`getLargeUpdateCount()`
`final int`
`getMaxFieldSize()`
`final int`
`getMaxRows()`
`final boolean`
`getMoreResults()`
Returns more results in the TDS stream.
`final boolean`
`getMoreResults(int mode)`
`final int`
`getQueryTimeout()`
`final String`
`getResponseBuffering()`
Returns the response buffering mode for this SQLServerStatement object.
`final ResultSet`
`getResultSet()`
`final int`
`getResultSetConcurrency()`
`final int`
`getResultSetHoldability()`
`final int`
`getResultSetType()`
`protected SQLServerStatementColumnEncryptionSetting`
`getStmtColumnEncriptionSetting()`
Returns the statement column encryption encryption setting
`final int`
`getUpdateCount()`
`final SQLWarning`
`getWarnings()`
`boolean`
`isClosed()`
`boolean`
`isCloseOnCompletion()`
`boolean`
`isPoolable()`
`boolean`
`isWrapperFor(Class<?> iface)`
`void`
`registerColumnEncryptionKeyStoreProvidersOnStatement(Map<String,SQLServerColumnEncryptionKeyStoreProvider> clientKeyStoreProviders)`
Registers statement-level key store providers, replacing all existing providers.
`final void`
`setCancelQueryTimeout(int seconds)`
Sets the `cancelQueryTimeout` property on this SQLServerStatement object to cancel `queryTimeout` set on `Connection` or `Statement` level.
`final void`
`setCursorName(String name)`
`final void`
`setEscapeProcessing(boolean enable)`
`final void`
`setFetchDirection(int nDir)`
`final void`
`setFetchSize(int rows)`
`final void`
`setLargeMaxRows(long max)`
`final void`
`setMaxFieldSize(int max)`
`final void`
`setMaxRows(int max)`
`void`
`setPoolable(boolean poolable)`
`final void`
`setQueryTimeout(int seconds)`
`final void`
`setResponseBuffering(String value)`
Sets the response buffering mode for this SQLServerStatement object to case-insensitive String full or adaptive.
`String`
`toString()`
Returns the statement's id for logging info
`<T> T`
`unwrap(Class<T> iface)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface java.sql.Statement

`enquoteIdentifier, enquoteLiteral, enquoteNCharLiteral, isSimpleIdentifier`

## Field Details

### stmtColumnEncriptionSetting

protected SQLServerStatementColumnEncryptionSetting stmtColumnEncriptionSetting
Column Encryption Override. Defaults to the connection setting, in which case it will be Enabled if columnEncryptionSetting = true in the connection setting, Disabled if false. This may also be used to set other behavior which overrides connection level setting.

## Method Details

### getStmtColumnEncriptionSetting

protected SQLServerStatementColumnEncryptionSetting getStmtColumnEncriptionSetting()
Returns the statement column encryption encryption setting

Returns:
  stmtColumnEncriptionSetting

### toString

public String toString()
Returns the statement's id for logging info

Overrides:
  `toString` in class `Object`

### close

public void close() throws SQLServerException

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Statement`
Throws:
  `SQLServerException`

### closeOnCompletion

public void closeOnCompletion() throws SQLException

Specified by:
  `closeOnCompletion` in interface `Statement`
Throws:
  `SQLException`

### executeQuery

public ResultSet executeQuery(String sql) throws SQLServerException, SQLTimeoutException

Specified by:
  `executeQuery` in interface `Statement`
Throws:
  `SQLServerException`
  `SQLTimeoutException`

### executeUpdate

public int executeUpdate(String sql) throws SQLServerException, SQLTimeoutException

Specified by:
  `executeUpdate` in interface `Statement`
Throws:
  `SQLServerException`
  `SQLTimeoutException`

### executeLargeUpdate

public long executeLargeUpdate(String sql) throws SQLServerException, SQLTimeoutException

Specified by:
  `executeLargeUpdate` in interface `Statement`
Throws:
  `SQLServerException`
  `SQLTimeoutException`

### execute

public boolean execute(String sql) throws SQLServerException, SQLTimeoutException

Specified by:
  `execute` in interface `Statement`
Throws:
  `SQLServerException`
  `SQLTimeoutException`

### getMaxFieldSize

public final int getMaxFieldSize() throws SQLServerException

Specified by:
  `getMaxFieldSize` in interface `Statement`
Throws:
  `SQLServerException`

### setMaxFieldSize

public final void setMaxFieldSize(int max) throws SQLServerException

Specified by:
  `setMaxFieldSize` in interface `Statement`
Throws:
  `SQLServerException`

### getMaxRows

public final int getMaxRows() throws SQLServerException

Specified by:
  `getMaxRows` in interface `Statement`
Throws:
  `SQLServerException`

### getLargeMaxRows

public final long getLargeMaxRows() throws SQLServerException

Specified by:
  `getLargeMaxRows` in interface `Statement`
Throws:
  `SQLServerException`

### setMaxRows

public final void setMaxRows(int max) throws SQLServerException

Specified by:
  `setMaxRows` in interface `Statement`
Throws:
  `SQLServerException`

### setLargeMaxRows

public final void setLargeMaxRows(long max) throws SQLServerException

Specified by:
  `setLargeMaxRows` in interface `Statement`
Throws:
  `SQLServerException`

### setEscapeProcessing

public final void setEscapeProcessing(boolean enable) throws SQLServerException

Specified by:
  `setEscapeProcessing` in interface `Statement`
Throws:
  `SQLServerException`

### getQueryTimeout

public final int getQueryTimeout() throws SQLServerException

Specified by:
  `getQueryTimeout` in interface `Statement`
Throws:
  `SQLServerException`

### setQueryTimeout

public final void setQueryTimeout(int seconds) throws SQLServerException

Specified by:
  `setQueryTimeout` in interface `Statement`
Throws:
  `SQLServerException`

### getCancelQueryTimeout

public final int getCancelQueryTimeout() throws SQLServerException
Description copied from interface: `ISQLServerStatement`
Returns the `cancelQueryTimeout` property set on this SQLServerStatement object.

Specified by:
  `getCancelQueryTimeout` in interface `ISQLServerStatement`
Returns:
  cancelQueryTimeout Time duration in seconds.
Throws:
  `SQLServerException` - if any error occurs

### setCancelQueryTimeout

public final void setCancelQueryTimeout(int seconds) throws SQLServerException
Description copied from interface: `ISQLServerStatement`
Sets the `cancelQueryTimeout` property on this SQLServerStatement object to cancel `queryTimeout` set on `Connection` or `Statement` level.

Specified by:
  `setCancelQueryTimeout` in interface `ISQLServerStatement`
Parameters:
  `seconds` - Time duration in seconds.
Throws:
  `SQLServerException` - if any error occurs

### cancel

public final void cancel() throws SQLServerException

Specified by:
  `cancel` in interface `Statement`
Throws:
  `SQLServerException`

### getWarnings

public final SQLWarning getWarnings() throws SQLServerException

Specified by:
  `getWarnings` in interface `Statement`
Throws:
  `SQLServerException`

### clearWarnings

public final void clearWarnings() throws SQLServerException

Specified by:
  `clearWarnings` in interface `Statement`
Throws:
  `SQLServerException`

### setCursorName

public final void setCursorName(String name) throws SQLServerException

Specified by:
  `setCursorName` in interface `Statement`
Throws:
  `SQLServerException`

### getResultSet

public final ResultSet getResultSet() throws SQLServerException

Specified by:
  `getResultSet` in interface `Statement`
Throws:
  `SQLServerException`

### getUpdateCount

public final int getUpdateCount() throws SQLServerException

Specified by:
  `getUpdateCount` in interface `Statement`
Throws:
  `SQLServerException`

### getLargeUpdateCount

public final long getLargeUpdateCount() throws SQLServerException

Specified by:
  `getLargeUpdateCount` in interface `Statement`
Throws:
  `SQLServerException`

### getMoreResults

public final boolean getMoreResults() throws SQLServerException
Returns more results in the TDS stream.

Specified by:
  `getMoreResults` in interface `Statement`
Returns:
  true if the next result is a ResultSet object; false if it is an integer (indicating that it is an update count or there are no more results).
Throws:
  `SQLServerException`

### setFetchDirection

public final void setFetchDirection(int nDir) throws SQLServerException

Specified by:
  `setFetchDirection` in interface `Statement`
Throws:
  `SQLServerException`

### getFetchDirection

public final int getFetchDirection() throws SQLServerException

Specified by:
  `getFetchDirection` in interface `Statement`
Throws:
  `SQLServerException`

### setFetchSize

public final void setFetchSize(int rows) throws SQLServerException

Specified by:
  `setFetchSize` in interface `Statement`
Throws:
  `SQLServerException`

### getFetchSize

public final int getFetchSize() throws SQLServerException

Specified by:
  `getFetchSize` in interface `Statement`
Throws:
  `SQLServerException`

### getResultSetConcurrency

public final int getResultSetConcurrency() throws SQLServerException

Specified by:
  `getResultSetConcurrency` in interface `Statement`
Throws:
  `SQLServerException`

### getResultSetType

public final int getResultSetType() throws SQLServerException

Specified by:
  `getResultSetType` in interface `Statement`
Throws:
  `SQLServerException`

### addBatch

public void addBatch(String sql) throws SQLServerException

Specified by:
  `addBatch` in interface `Statement`
Throws:
  `SQLServerException`

### clearBatch

public void clearBatch() throws SQLServerException

Specified by:
  `clearBatch` in interface `Statement`
Throws:
  `SQLServerException`

### executeBatch

public int[] executeBatch() throws SQLServerException, BatchUpdateException, SQLTimeoutException
Sends a batch of statements to the database.

Specified by:
  `executeBatch` in interface `Statement`
Throws:
  `SQLServerException`
  `BatchUpdateException`
  `SQLTimeoutException`

### executeLargeBatch

public long[] executeLargeBatch() throws SQLServerException, BatchUpdateException, SQLTimeoutException

Specified by:
  `executeLargeBatch` in interface `Statement`
Throws:
  `SQLServerException`
  `BatchUpdateException`
  `SQLTimeoutException`

### getConnection

public final Connection getConnection() throws SQLServerException
Returns the statement's connection.

Specified by:
  `getConnection` in interface `Statement`
Returns:
  the connection
Throws:
  `SQLServerException` - when an error occurs

### getResultSetHoldability

public final int getResultSetHoldability() throws SQLException

Specified by:
  `getResultSetHoldability` in interface `Statement`
Throws:
  `SQLException`

### execute

public final boolean execute(String sql, int autoGeneratedKeys) throws SQLServerException, SQLTimeoutException

Specified by:
  `execute` in interface `Statement`
Throws:
  `SQLServerException`
  `SQLTimeoutException`

### execute

public final boolean execute(String sql, int[] columnIndexes) throws SQLServerException, SQLTimeoutException

Specified by:
  `execute` in interface `Statement`
Throws:
  `SQLServerException`
  `SQLTimeoutException`

### execute

public final boolean execute(String sql, String[] columnNames) throws SQLServerException, SQLTimeoutException

Specified by:
  `execute` in interface `Statement`
Throws:
  `SQLServerException`
  `SQLTimeoutException`

### executeUpdate

public final int executeUpdate(String sql, int autoGeneratedKeys) throws SQLServerException, SQLTimeoutException

Specified by:
  `executeUpdate` in interface `Statement`
Throws:
  `SQLServerException`
  `SQLTimeoutException`

### executeLargeUpdate

public final long executeLargeUpdate(String sql, int autoGeneratedKeys) throws SQLServerException, SQLTimeoutException

Specified by:
  `executeLargeUpdate` in interface `Statement`
Throws:
  `SQLServerException`
  `SQLTimeoutException`

### executeUpdate

public final int executeUpdate(String sql, int[] columnIndexes) throws SQLServerException, SQLTimeoutException

Specified by:
  `executeUpdate` in interface `Statement`
Throws:
  `SQLServerException`
  `SQLTimeoutException`

### executeLargeUpdate

public final long executeLargeUpdate(String sql, int[] columnIndexes) throws SQLServerException, SQLTimeoutException

Specified by:
  `executeLargeUpdate` in interface `Statement`
Throws:
  `SQLServerException`
  `SQLTimeoutException`

### executeUpdate

public final int executeUpdate(String sql, String[] columnNames) throws SQLServerException, SQLTimeoutException

Specified by:
  `executeUpdate` in interface `Statement`
Throws:
  `SQLServerException`
  `SQLTimeoutException`

### executeLargeUpdate

public final long executeLargeUpdate(String sql, String[] columnNames) throws SQLServerException, SQLTimeoutException

Specified by:
  `executeLargeUpdate` in interface `Statement`
Throws:
  `SQLServerException`
  `SQLTimeoutException`

### getGeneratedKeys

public final ResultSet getGeneratedKeys() throws SQLServerException

Specified by:
  `getGeneratedKeys` in interface `Statement`
Throws:
  `SQLServerException`

### getMoreResults

public final boolean getMoreResults(int mode) throws SQLException

Specified by:
  `getMoreResults` in interface `Statement`
Throws:
  `SQLException`

### isClosed

public boolean isClosed() throws SQLException

Specified by:
  `isClosed` in interface `Statement`
Throws:
  `SQLException`

### isCloseOnCompletion

public boolean isCloseOnCompletion() throws SQLException

Specified by:
  `isCloseOnCompletion` in interface `Statement`
Throws:
  `SQLException`

### isPoolable

public boolean isPoolable() throws SQLException

Specified by:
  `isPoolable` in interface `Statement`
Throws:
  `SQLException`

### setPoolable

public void setPoolable(boolean poolable) throws SQLException

Specified by:
  `setPoolable` in interface `Statement`
Throws:
  `SQLException`

### isWrapperFor

public boolean isWrapperFor(Class<?> iface) throws SQLException

Specified by:
  `isWrapperFor` in interface `Wrapper`
Throws:
  `SQLException`

### unwrap

public <T> T unwrap(Class<T> iface) throws SQLException

Specified by:
  `unwrap` in interface `Wrapper`
Throws:
  `SQLException`

### setResponseBuffering

public final void setResponseBuffering(String value) throws SQLServerException
Description copied from interface: `ISQLServerStatement`
Sets the response buffering mode for this SQLServerStatement object to case-insensitive String full or adaptive.

Response buffering controls the driver's buffering of responses from SQL Server.

Possible values are:

"full" - Fully buffer the response at execution time.

"adaptive" - Data Pipe adaptive buffering

Specified by:
  `setResponseBuffering` in interface `ISQLServerStatement`
Parameters:
  `value` - A String that contains the response buffering mode. The valid mode can be one of the following case-insensitive Strings: full or adaptive.
Throws:
  `SQLServerException` - If there are any errors in setting the response buffering mode.

### getResponseBuffering

public final String getResponseBuffering() throws SQLServerException
Description copied from interface: `ISQLServerStatement`
Returns the response buffering mode for this SQLServerStatement object.

Specified by:
  `getResponseBuffering` in interface `ISQLServerStatement`
Returns:
  A String that contains a lower-case full or adaptive.
Throws:
  `SQLServerException` - If there are any errors in retrieving the response buffering mode.

### registerColumnEncryptionKeyStoreProvidersOnStatement

public void registerColumnEncryptionKeyStoreProvidersOnStatement(Map<String,SQLServerColumnEncryptionKeyStoreProvider> clientKeyStoreProviders) throws SQLServerException
Registers statement-level key store providers, replacing all existing providers.

Parameters:
  `clientKeyStoreProviders` - a map containing the store providers information.
Throws:
  `SQLServerException` - when an error occurs