public class SQLServerConnection extends Object implements ISQLServerConnection
SQLServerConnection manages transaction control for all statements that were created from it. SQLServerConnection may participate in XA distributed transactions managed via an XAResource adapter.
SQLServerConnection instantiates a new TDSChannel object for use by itself and all statement objects that are created under this connection. SQLServerConnection is thread safe.
SQLServerConnection manages a pool of prepared statement handles. Prepared statements are prepared once and typically executed many times with different data values for their parameters. Prepared statements are also maintained across logical (pooled) connection closes.
SQLServerConnection is not thread safe, however multiple statements created from a single connection can be processing simultaneously in concurrent threads.
This class's public functions need to be kept identical to the SQLServerConnectionPoolProxy's.
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.
TRANSACTION_SNAPSHOTTRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE| Modifier and Type | Method and Description |
|---|---|
void |
abort(Executor executor) |
void |
clearWarnings() |
void |
close() |
void |
closeUnreferencedPreparedStatementHandles()
Forces the un-prepare requests for any outstanding discarded prepared statements to be executed.
|
void |
commit()
Commit a transcation.
|
Array |
createArrayOf(String typeName,
Object[] elements) |
Blob |
createBlob() |
Clob |
createClob() |
NClob |
createNClob() |
SQLXML |
createSQLXML() |
Statement |
createStatement() |
Statement |
createStatement(int resultSetType,
int resultSetConcurrency) |
Statement |
createStatement(int nType,
int nConcur,
int resultSetHoldability) |
Statement |
createStatement(int nType,
int nConcur,
int resultSetHoldability,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting) |
Struct |
createStruct(String typeName,
Object[] attributes) |
boolean |
getAutoCommit() |
String |
getCatalog() |
UUID |
getClientConnectionId()
Retrieves the clientConnectionID.
|
Properties |
getClientInfo() |
String |
getClientInfo(String name) |
static Map<String,List<String>> |
getColumnEncryptionTrustedMasterKeyPaths()
Retrieves the Trusted Master Key Paths.
|
boolean |
getDisableStatementPooling()
Returns true if statement pooling is disabled.
|
int |
getDiscardedServerPreparedStatementCount()
Returns the number of currently outstanding prepared statement un-prepare actions.
|
boolean |
getEnablePrepareOnFirstPreparedStatementCall()
Returns the behavior for a specific connection instance.
|
int |
getHoldability() |
DatabaseMetaData |
getMetaData() |
int |
getNetworkTimeout() |
String |
getSchema() |
boolean |
getSendTimeAsDatetime()
Checks the sendTimeAsDatetime property.
|
int |
getServerPreparedStatementDiscardThreshold()
Returns the behavior for a specific connection instance.
|
int |
getStatementHandleCacheEntryCount()
Returns the current number of pooled prepared statement handles.
|
int |
getStatementPoolingCacheSize()
Returns the size of the prepared statement cache for this connection.
|
int |
getTransactionIsolation() |
Map<String,Class<?>> |
getTypeMap() |
SQLWarning |
getWarnings() |
boolean |
isClosed() |
boolean |
isReadOnly() |
boolean |
isStatementPoolingEnabled()
Whether statement pooling is enabled or not for this connection.
|
boolean |
isValid(int timeout)
Determine whether the connection is still valid.
|
boolean |
isWrapperFor(Class<?> iface) |
String |
nativeSQL(String sql) |
CallableStatement |
prepareCall(String sql) |
CallableStatement |
prepareCall(String sql,
int resultSetType,
int resultSetConcurrency) |
CallableStatement |
prepareCall(String sql,
int nType,
int nConcur,
int resultSetHoldability) |
CallableStatement |
prepareCall(String sql,
int nType,
int nConcur,
int resultSetHoldability,
SQLServerStatementColumnEncryptionSetting stmtColEncSetiing) |
PreparedStatement |
prepareStatement(String sql) |
PreparedStatement |
prepareStatement(String sql,
int flag) |
PreparedStatement |
prepareStatement(String sql,
int[] columnIndexes) |
PreparedStatement |
prepareStatement(String sql,
int[] columnIndexes,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting)
Creates a default
PreparedStatement object capable of returning the auto-generated keys designated by the given array. |
PreparedStatement |
prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency) |
PreparedStatement |
prepareStatement(String sql,
int nType,
int nConcur,
int resultSetHoldability) |
PreparedStatement |
prepareStatement(String sql,
int nType,
int nConcur,
int resultSetHoldability,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting)
Creates a
PreparedStatement object that will generate ResultSet objects with the given type, concurrency, and
holdability. |
PreparedStatement |
prepareStatement(String sql,
int flag,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting)
Creates a default
PreparedStatement object that has the capability to retrieve auto-generated keys. |
PreparedStatement |
prepareStatement(String sql,
String[] columnNames) |
PreparedStatement |
prepareStatement(String sql,
String[] columnNames,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting)
Creates a default
PreparedStatement object capable of returning the auto-generated keys designated by the given array. |
static void |
registerColumnEncryptionKeyStoreProviders(Map<String,SQLServerColumnEncryptionKeyStoreProvider> clientKeyStoreProviders)
Registers key store providers in the globalCustomColumnEncryptionKeyStoreProviders.
|
void |
releaseSavepoint(Savepoint savepoint) |
static void |
removeColumnEncryptionTrustedMasterKeyPaths(String server)
Removes the trusted Master key Path from the columnEncryptionTrustedMasterKeyPaths.
|
void |
rollback()
Rollback a transcation.
|
void |
rollback(Savepoint s) |
void |
setAutoCommit(boolean newAutoCommitMode) |
void |
setCatalog(String catalog) |
void |
setClientInfo(Properties properties) |
void |
setClientInfo(String name,
String value) |
static void |
setColumnEncryptionKeyCacheTtl(int columnEncryptionKeyCacheTTL,
TimeUnit unit)
Sets time-to-live for column encryption key entries in the column encryption key cache for the Always Encrypted feature.
|
static void |
setColumnEncryptionTrustedMasterKeyPaths(Map<String,List<String>> trustedKeyPaths)
Sets Trusted Master Key Paths in the columnEncryptionTrustedMasterKeyPaths.
|
void |
setDisableStatementPooling(boolean value)
Sets statement pooling to true or false;
|
void |
setEnablePrepareOnFirstPreparedStatementCall(boolean value)
Specifies the behavior for a specific connection instance.
|
void |
setHoldability(int holdability) |
void |
setNetworkTimeout(Executor executor,
int timeout) |
void |
setReadOnly(boolean readOnly) |
Savepoint |
setSavepoint() |
Savepoint |
setSavepoint(String sName) |
void |
setSchema(String schema) |
void |
setSendTimeAsDatetime(boolean sendTimeAsDateTimeValue)
Modifies the setting of the sendTimeAsDatetime connection property.
|
void |
setServerPreparedStatementDiscardThreshold(int value)
Specifies the behavior for a specific connection instance.
|
void |
setStatementPoolingCacheSize(int value)
Specifies the size of the prepared statement cache for this connection.
|
void |
setTransactionIsolation(int level) |
void |
setTypeMap(Map<String,Class<?>> map) |
String |
toString()
This is a helper function to provide an ID string suitable for tracing.
|
<T> T |
unwrap(Class<T> iface) |
static void |
updateColumnEncryptionTrustedMasterKeyPaths(String server,
List<String> trustedKeyPaths)
Updates the columnEncryptionTrustedMasterKeyPaths with the new Server and trustedKeyPaths.
|
public final boolean getSendTimeAsDatetime()
public static void registerColumnEncryptionKeyStoreProviders(Map<String,SQLServerColumnEncryptionKeyStoreProvider> clientKeyStoreProviders) throws SQLServerException
clientKeyStoreProviders - a map containing the store providers information.SQLServerException - when an error occurspublic static void setColumnEncryptionTrustedMasterKeyPaths(Map<String,List<String>> trustedKeyPaths)
trustedKeyPaths - all master key paths that are trustedpublic static void updateColumnEncryptionTrustedMasterKeyPaths(String server, List<String> trustedKeyPaths)
server - String server nametrustedKeyPaths - all master key paths that are trustedpublic static void removeColumnEncryptionTrustedMasterKeyPaths(String server)
server - String server namepublic static Map<String,List<String>> getColumnEncryptionTrustedMasterKeyPaths()
public UUID getClientConnectionId() throws SQLServerException
getClientConnectionId in interface ISQLServerConnectionSQLServerException - when an error occurspublic String toString()
public Statement createStatement() throws SQLServerException
createStatement in interface ConnectionSQLServerExceptionpublic PreparedStatement prepareStatement(String sql) throws SQLServerException
prepareStatement in interface ConnectionSQLServerExceptionpublic CallableStatement prepareCall(String sql) throws SQLServerException
prepareCall in interface ConnectionSQLServerExceptionpublic String nativeSQL(String sql) throws SQLServerException
nativeSQL in interface ConnectionSQLServerExceptionpublic void setAutoCommit(boolean newAutoCommitMode)
throws SQLServerException
setAutoCommit in interface ConnectionSQLServerExceptionpublic boolean getAutoCommit()
throws SQLServerException
getAutoCommit in interface ConnectionSQLServerExceptionpublic void commit()
throws SQLServerException
commit in interface ConnectionSQLServerException - if no transaction exists.public void rollback()
throws SQLServerException
rollback in interface ConnectionSQLServerException - if no transaction exists or if the connection is in auto-commit mode.public void abort(Executor executor) throws SQLException
abort in interface ConnectionSQLExceptionpublic void close()
throws SQLServerException
close in interface AutoCloseableclose in interface ConnectionSQLServerExceptionpublic boolean isClosed()
throws SQLServerException
isClosed in interface ConnectionSQLServerExceptionpublic DatabaseMetaData getMetaData() throws SQLServerException
getMetaData in interface ConnectionSQLServerExceptionpublic void setReadOnly(boolean readOnly)
throws SQLServerException
setReadOnly in interface ConnectionSQLServerExceptionpublic boolean isReadOnly()
throws SQLServerException
isReadOnly in interface ConnectionSQLServerExceptionpublic void setCatalog(String catalog) throws SQLServerException
setCatalog in interface ConnectionSQLServerExceptionpublic String getCatalog() throws SQLServerException
getCatalog in interface ConnectionSQLServerExceptionpublic void setTransactionIsolation(int level)
throws SQLServerException
setTransactionIsolation in interface ConnectionSQLServerExceptionpublic int getTransactionIsolation()
throws SQLServerException
getTransactionIsolation in interface ConnectionSQLServerExceptionpublic SQLWarning getWarnings() throws SQLServerException
getWarnings in interface ConnectionSQLServerExceptionpublic void clearWarnings()
throws SQLServerException
clearWarnings in interface ConnectionSQLServerExceptionpublic Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLServerException
createStatement in interface ConnectionSQLServerExceptionpublic PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLServerException
prepareStatement in interface ConnectionSQLServerExceptionpublic CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLServerException
prepareCall in interface ConnectionSQLServerExceptionpublic void setTypeMap(Map<String,Class<?>> map) throws SQLServerException
setTypeMap in interface ConnectionSQLServerExceptionpublic Map<String,Class<?>> getTypeMap() throws SQLServerException
getTypeMap in interface ConnectionSQLServerExceptionpublic Statement createStatement(int nType, int nConcur, int resultSetHoldability) throws SQLServerException
createStatement in interface ConnectionSQLServerExceptionpublic Statement createStatement(int nType, int nConcur, int resultSetHoldability, SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException
SQLServerExceptionpublic PreparedStatement prepareStatement(String sql, int nType, int nConcur, int resultSetHoldability) throws SQLServerException
prepareStatement in interface ConnectionSQLServerExceptionpublic PreparedStatement prepareStatement(String sql, int nType, int nConcur, int resultSetHoldability, SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException
PreparedStatement object that will generate ResultSet objects with the given type, concurrency, and
holdability.
This method is the same as the prepareStatement method above, but it allows the default result set type, concurrency, and
holdability to be overridden.
sql - a String object that is the SQL statement to be sent to the database; may contain one or more '?' IN parametersnType - one of the following ResultSet constants: ResultSet.TYPE_FORWARD_ONLY,
ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVEnConcur - one of the following ResultSet constants: ResultSet.CONCUR_READ_ONLY or
ResultSet.CONCUR_UPDATABLEresultSetHoldability - one of the following ResultSet constants: ResultSet.HOLD_CURSORS_OVER_COMMIT or
ResultSet.CLOSE_CURSORS_AT_COMMITstmtColEncSetting - Specifies how data will be sent and received when reading and writing encrypted columns.PreparedStatement object, containing the pre-compiled SQL statement, that will generate ResultSet
objects with the given type, concurrency, and holdabilitySQLServerException - if a database access error occurs, this method is called on a closed connection or the given parameters are not
ResultSet constants indicating type, concurrency, and holdabilitypublic CallableStatement prepareCall(String sql, int nType, int nConcur, int resultSetHoldability) throws SQLServerException
prepareCall in interface ConnectionSQLServerExceptionpublic CallableStatement prepareCall(String sql, int nType, int nConcur, int resultSetHoldability, SQLServerStatementColumnEncryptionSetting stmtColEncSetiing) throws SQLServerException
SQLServerExceptionpublic PreparedStatement prepareStatement(String sql, int flag) throws SQLServerException
prepareStatement in interface ConnectionSQLServerExceptionpublic PreparedStatement prepareStatement(String sql, int flag, SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException
PreparedStatement object that has the capability to retrieve auto-generated keys. The given constant tells the
driver whether it should make auto-generated keys available for retrieval. This parameter is ignored if the SQL statement is not an
INSERT statement, or an SQL statement able to return auto-generated keys (the list of such statements is vendor-specific).
Note: This method is optimized for handling parametric SQL statements that benefit from precompilation. If the driver supports
precompilation, the method prepareStatement will send the statement to the database for precompilation. Some drivers may not
support precompilation. In this case, the statement may not be sent to the database until the PreparedStatement object is
executed. This has no direct effect on users; however, it does affect which methods throw certain SQLExceptions.
Result sets created using the returned PreparedStatement object will by default be type TYPE_FORWARD_ONLY and have a
concurrency level of CONCUR_READ_ONLY. The holdability of the created result sets can be determined by calling
getHoldability().
sql - an SQL statement that may contain one or more '?' IN parameter placeholdersflag - a flag indicating whether auto-generated keys should be returned; one of Statement.RETURN_GENERATED_KEYS or
Statement.NO_GENERATED_KEYSstmtColEncSetting - Specifies how data will be sent and received when reading and writing encrypted columns.PreparedStatement object, containing the pre-compiled SQL statement, that will have the capability of returning
auto-generated keysSQLServerException - if a database access error occurs, this method is called on a closed connection or the given parameter is not a
Statement constant indicating whether auto-generated keys should be returnedpublic PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLServerException
prepareStatement in interface ConnectionSQLServerExceptionpublic PreparedStatement prepareStatement(String sql, int[] columnIndexes, SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException
PreparedStatement object capable of returning the auto-generated keys designated by the given array. This array
contains the indexes of the columns in the target table that contain the auto-generated keys that should be made available. The driver will
ignore the array if the SQL statement is not an INSERT statement, or an SQL statement able to return auto-generated keys (the list
of such statements is vendor-specific).
An SQL statement with or without IN parameters can be pre-compiled and stored in a PreparedStatement object. This object can then
be used to efficiently execute this statement multiple times.
Note: This method is optimized for handling parametric SQL statements that benefit from precompilation. If the driver supports
precompilation, the method prepareStatement will send the statement to the database for precompilation. Some drivers may not
support precompilation. In this case, the statement may not be sent to the database until the PreparedStatement object is
executed. This has no direct effect on users; however, it does affect which methods throw certain SQLExceptions.
Result sets created using the returned PreparedStatement object will by default be type TYPE_FORWARD_ONLY and have a
concurrency level of CONCUR_READ_ONLY. The holdability of the created result sets can be determined by calling
getHoldability().
sql - an SQL statement that may contain one or more '?' IN parameter placeholderscolumnIndexes - an array of column indexes indicating the columns that should be returned from the inserted row or rowsstmtColEncSetting - Specifies how data will be sent and received when reading and writing encrypted columns.PreparedStatement object, containing the pre-compiled statement, that is capable of returning the auto-generated
keys designated by the given array of column indexesSQLServerException - if a database access error occurs or this method is called on a closed connectionpublic PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLServerException
prepareStatement in interface ConnectionSQLServerExceptionpublic PreparedStatement prepareStatement(String sql, String[] columnNames, SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException
PreparedStatement object capable of returning the auto-generated keys designated by the given array. This array
contains the names of the columns in the target table that contain the auto-generated keys that should be returned. The driver will ignore the
array if the SQL statement is not an INSERT statement, or an SQL statement able to return auto-generated keys (the list of such
statements is vendor-specific).
An SQL statement with or without IN parameters can be pre-compiled and stored in a PreparedStatement object. This object can then
be used to efficiently execute this statement multiple times.
Note: This method is optimized for handling parametric SQL statements that benefit from precompilation. If the driver supports
precompilation, the method prepareStatement will send the statement to the database for precompilation. Some drivers may not
support precompilation. In this case, the statement may not be sent to the database until the PreparedStatement object is
executed. This has no direct effect on users; however, it does affect which methods throw certain SQLExceptions.
Result sets created using the returned PreparedStatement object will by default be type TYPE_FORWARD_ONLY and have a
concurrency level of CONCUR_READ_ONLY. The holdability of the created result sets can be determined by calling
getHoldability().
sql - an SQL statement that may contain one or more '?' IN parameter placeholderscolumnNames - an array of column names indicating the columns that should be returned from the inserted row or rowsstmtColEncSetting - Specifies how data will be sent and received when reading and writing encrypted columns.PreparedStatement object, containing the pre-compiled statement, that is capable of returning the auto-generated
keys designated by the given array of column namesSQLServerException - if a database access error occurs or this method is called on a closed connectionpublic void releaseSavepoint(Savepoint savepoint) throws SQLServerException
releaseSavepoint in interface ConnectionSQLServerExceptionpublic Savepoint setSavepoint(String sName) throws SQLServerException
setSavepoint in interface ConnectionSQLServerExceptionpublic Savepoint setSavepoint() throws SQLServerException
setSavepoint in interface ConnectionSQLServerExceptionpublic void rollback(Savepoint s) throws SQLServerException
rollback in interface ConnectionSQLServerExceptionpublic int getHoldability()
throws SQLServerException
getHoldability in interface ConnectionSQLServerExceptionpublic void setHoldability(int holdability)
throws SQLServerException
setHoldability in interface ConnectionSQLServerExceptionpublic int getNetworkTimeout()
throws SQLException
getNetworkTimeout in interface ConnectionSQLExceptionpublic void setNetworkTimeout(Executor executor, int timeout) throws SQLException
setNetworkTimeout in interface ConnectionSQLExceptionpublic String getSchema() throws SQLException
getSchema in interface ConnectionSQLExceptionpublic void setSchema(String schema) throws SQLException
setSchema in interface ConnectionSQLExceptionpublic void setSendTimeAsDatetime(boolean sendTimeAsDateTimeValue)
sendTimeAsDateTimeValue - enables/disables setting the sendTimeAsDatetime connection property. For more information about how the Microsoft JDBC Driver for
SQL Server configures java.sql.Time values before sending them to the server, see
Configuring How java.sql.Time Values are Sent to the
Server.public Array createArrayOf(String typeName, Object[] elements) throws SQLException
createArrayOf in interface ConnectionSQLExceptionpublic Blob createBlob() throws SQLException
createBlob in interface ConnectionSQLExceptionpublic Clob createClob() throws SQLException
createClob in interface ConnectionSQLExceptionpublic NClob createNClob() throws SQLException
createNClob in interface ConnectionSQLExceptionpublic SQLXML createSQLXML() throws SQLException
createSQLXML in interface ConnectionSQLExceptionpublic Struct createStruct(String typeName, Object[] attributes) throws SQLException
createStruct in interface ConnectionSQLExceptionpublic Properties getClientInfo() throws SQLException
getClientInfo in interface ConnectionSQLExceptionpublic String getClientInfo(String name) throws SQLException
getClientInfo in interface ConnectionSQLExceptionpublic void setClientInfo(Properties properties) throws SQLClientInfoException
setClientInfo in interface ConnectionSQLClientInfoExceptionpublic void setClientInfo(String name, String value) throws SQLClientInfoException
setClientInfo in interface ConnectionSQLClientInfoExceptionpublic boolean isValid(int timeout)
throws SQLException
isValid in interface Connectiontimeout - The time in seconds to wait for the database operation used to validate the connection to complete. If the timeout period expires
before the operation completes, this method returns false. A value of 0 indicates a timeout is not applied to the database
operation. Note that if the value is 0, the call to isValid may block indefinitely if the connection is not valid...SQLException - if the value supplied for the timeout is less than 0.public boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor in interface WrapperSQLExceptionpublic <T> T unwrap(Class<T> iface) throws SQLException
unwrap in interface WrapperSQLExceptionpublic static void setColumnEncryptionKeyCacheTtl(int columnEncryptionKeyCacheTTL,
TimeUnit unit)
throws SQLServerException
columnEncryptionKeyCacheTTL - The timeunit in secondsunit - The Timeunit.SQLServerException - when an error occurspublic int getDiscardedServerPreparedStatementCount()
public void closeUnreferencedPreparedStatementHandles()
public boolean getEnablePrepareOnFirstPreparedStatementCall()
public void setEnablePrepareOnFirstPreparedStatementCall(boolean value)
value - Changes the setting per the description.public int getServerPreparedStatementDiscardThreshold()
public void setServerPreparedStatementDiscardThreshold(int value)
value - Changes the setting per the description.public boolean getDisableStatementPooling()
public void setDisableStatementPooling(boolean value)
value - public int getStatementPoolingCacheSize()
public int getStatementHandleCacheEntryCount()
public boolean isStatementPoolingEnabled()
public void setStatementPoolingCacheSize(int value)
value - The new cache size.Copyright © 2018 Microsoft Corporation. All rights reserved.