com.microsoft.sqlserver.jdbc

## Class SQLServerConnection

- java.lang.Object
- - com.microsoft.sqlserver.jdbc.SQLServerConnection

All Implemented Interfaces:
  ISQLServerConnection, AutoCloseable, Connection, Wrapper

    public class SQLServerConnection
    extends Object
    implements ISQLServerConnection

SQLServerConnection implements a JDBC connection to SQL Server. SQLServerConnections support JDBC connection pooling and may be either physical JDBC connections or logical JDBC connections.
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.

### Field Summary

### Fields inherited from interface com.microsoft.sqlserver.jdbc.ISQLServerConnection

`TRANSACTION_SNAPSHOT`

### Fields inherited from interface java.sql.Connection

`TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `abort(Executor executor)`
`void` `clearWarnings()`
`void` `close()`
`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 statementHoldability)`
`Statement` `createStatement(int nType, int nConcur, int statementHoldability, SQLServerStatementColumnEncryptionSetting stmtColEncSetting)`
`Struct` `createStruct(String typeName, Object[] attributes)`
`boolean` `getAutoCommit()`
`String` `getCatalog()`
`UUID` `getClientConnectionId()`
`Properties` `getClientInfo()`
`String` `getClientInfo(String name)`
`static Map<String,List<String>>` `getColumnEncryptionTrustedMasterKeyPaths()`
`int` `getHoldability()`
`DatabaseMetaData` `getMetaData()`
`int` `getNetworkTimeout()`
`String` `getSchema()`
`boolean` `getSendTimeAsDatetime()`
`int` `getTransactionIsolation()`
`Map<String,Class<?>>` `getTypeMap()`
`SQLWarning` `getWarnings()`
`boolean` `isClosed()`
`boolean` `isReadOnly()`
`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 statementHoldability)`
`CallableStatement` `prepareCall(String sql, int nType, int nConcur, int statementHoldability, 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)`
`PreparedStatement` `prepareStatement(String sql, int resultSetType, int resultSetConcurrency)`
`PreparedStatement` `prepareStatement(String sql, int nType, int nConcur, int statementHoldability)`
`PreparedStatement` `prepareStatement(String sql, int nType, int nConcur, int statementHoldability, SQLServerStatementColumnEncryptionSetting stmtColEncSetting)`
`PreparedStatement` `prepareStatement(String sql, int flag, SQLServerStatementColumnEncryptionSetting stmtColEncSetting)`
`PreparedStatement` `prepareStatement(String sql, String[] columnNames)`
`PreparedStatement` `prepareStatement(String sql, String[] columnNames, SQLServerStatementColumnEncryptionSetting stmtColEncSetting)`
`static void` `registerColumnEncryptionKeyStoreProviders(Map<String,SQLServerColumnEncryptionKeyStoreProvider> clientKeyStoreProviders)`
`void` `releaseSavepoint(Savepoint savepoint)`
`static void` `removeColumnEncryptionTrustedMasterKeyPaths(String server)`
`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)`
`static void` `setColumnEncryptionTrustedMasterKeyPaths(Map<String,List<String>> trustedKeyPaths)`
`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)`
`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)`

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

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

### Method Detail

#### getSendTimeAsDatetime

    public final boolean getSendTimeAsDatetime()

#### registerColumnEncryptionKeyStoreProviders

    public static void registerColumnEncryptionKeyStoreProviders(Map<String,SQLServerColumnEncryptionKeyStoreProvider> clientKeyStoreProviders)
                                                          throws SQLServerException

Throws:
  `SQLServerException`

#### setColumnEncryptionTrustedMasterKeyPaths

    public static void setColumnEncryptionTrustedMasterKeyPaths(Map<String,List<String>> trustedKeyPaths)

#### updateColumnEncryptionTrustedMasterKeyPaths

    public static void updateColumnEncryptionTrustedMasterKeyPaths(String server,
                                                                   List<String> trustedKeyPaths)

#### removeColumnEncryptionTrustedMasterKeyPaths

    public static void removeColumnEncryptionTrustedMasterKeyPaths(String server)

#### getColumnEncryptionTrustedMasterKeyPaths

    public static Map<String,List<String>> getColumnEncryptionTrustedMasterKeyPaths()

#### getClientConnectionId

    public UUID getClientConnectionId()
                               throws SQLServerException

Specified by:
  `getClientConnectionId` in interface `ISQLServerConnection`
Throws:
  `SQLServerException`

#### toString

    public String toString()

This is a helper function to provide an ID string suitable for tracing.

Overrides:
  `toString` in class `Object`

#### createStatement

    public Statement createStatement()
                              throws SQLServerException

Specified by:
  `createStatement` in interface `Connection`
Throws:
  `SQLServerException`

#### prepareStatement

    public PreparedStatement prepareStatement(String sql)
                                       throws SQLServerException

Specified by:
  `prepareStatement` in interface `Connection`
Throws:
  `SQLServerException`

#### prepareCall

    public CallableStatement prepareCall(String sql)
                                  throws SQLServerException

Specified by:
  `prepareCall` in interface `Connection`
Throws:
  `SQLServerException`

#### nativeSQL

    public String nativeSQL(String sql)
                     throws SQLServerException

Specified by:
  `nativeSQL` in interface `Connection`
Throws:
  `SQLServerException`

#### setAutoCommit

    public void setAutoCommit(boolean newAutoCommitMode)
                       throws SQLServerException

Specified by:
  `setAutoCommit` in interface `Connection`
Throws:
  `SQLServerException`

#### getAutoCommit

    public boolean getAutoCommit()
                          throws SQLServerException

Specified by:
  `getAutoCommit` in interface `Connection`
Throws:
  `SQLServerException`

#### commit

    public void commit()
                throws SQLServerException

Commit a transcation. Per our transaction spec, see also SDT#410729, a commit in autocommit mode = true is a NO-OP.

Specified by:
  `commit` in interface `Connection`
Throws:
  `SQLServerException` - if no transaction exists.

#### rollback

    public void rollback()
                  throws SQLServerException

Rollback a transcation.

Specified by:
  `rollback` in interface `Connection`
Throws:
  `SQLServerException` - if no transaction exists or if the connection is in auto-commit mode.

#### abort

    public void abort(Executor executor)
               throws SQLException

Specified by:
  `abort` in interface `Connection`
Throws:
  `SQLException`

#### close

    public void close()
               throws SQLServerException

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

#### isClosed

    public boolean isClosed()
                     throws SQLServerException

Specified by:
  `isClosed` in interface `Connection`
Throws:
  `SQLServerException`

#### getMetaData

    public DatabaseMetaData getMetaData()
                                 throws SQLServerException

Specified by:
  `getMetaData` in interface `Connection`
Throws:
  `SQLServerException`

#### setReadOnly

    public void setReadOnly(boolean readOnly)
                     throws SQLServerException

Specified by:
  `setReadOnly` in interface `Connection`
Throws:
  `SQLServerException`

#### isReadOnly

    public boolean isReadOnly()
                       throws SQLServerException

Specified by:
  `isReadOnly` in interface `Connection`
Throws:
  `SQLServerException`

#### setCatalog

    public void setCatalog(String catalog)
                    throws SQLServerException

Specified by:
  `setCatalog` in interface `Connection`
Throws:
  `SQLServerException`

#### getCatalog

    public String getCatalog()
                      throws SQLServerException

Specified by:
  `getCatalog` in interface `Connection`
Throws:
  `SQLServerException`

#### setTransactionIsolation

    public void setTransactionIsolation(int level)
                                 throws SQLServerException

Specified by:
  `setTransactionIsolation` in interface `Connection`
Throws:
  `SQLServerException`

#### getTransactionIsolation

    public int getTransactionIsolation()
                                throws SQLServerException

Specified by:
  `getTransactionIsolation` in interface `Connection`
Throws:
  `SQLServerException`

#### getWarnings

    public SQLWarning getWarnings()
                           throws SQLServerException

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

#### clearWarnings

    public void clearWarnings()
                       throws SQLServerException

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

#### createStatement

    public Statement createStatement(int resultSetType,
                                     int resultSetConcurrency)
                              throws SQLServerException

Specified by:
  `createStatement` in interface `Connection`
Throws:
  `SQLServerException`

#### prepareStatement

    public PreparedStatement prepareStatement(String sql,
                                              int resultSetType,
                                              int resultSetConcurrency)
                                       throws SQLServerException

Specified by:
  `prepareStatement` in interface `Connection`
Throws:
  `SQLServerException`

#### prepareCall

    public CallableStatement prepareCall(String sql,
                                         int resultSetType,
                                         int resultSetConcurrency)
                                  throws SQLServerException

Specified by:
  `prepareCall` in interface `Connection`
Throws:
  `SQLServerException`

#### setTypeMap

    public void setTypeMap(Map<String,Class<?>> map)
                    throws SQLServerException

Specified by:
  `setTypeMap` in interface `Connection`
Throws:
  `SQLServerException`

#### getTypeMap

    public Map<String,Class<?>> getTypeMap()
                                    throws SQLServerException

Specified by:
  `getTypeMap` in interface `Connection`
Throws:
  `SQLServerException`

#### createStatement

    public Statement createStatement(int nType,
                                     int nConcur,
                                     int statementHoldability)
                              throws SQLServerException

Specified by:
  `createStatement` in interface `Connection`
Throws:
  `SQLServerException`

#### createStatement

    public Statement createStatement(int nType,
                                     int nConcur,
                                     int statementHoldability,
                                     SQLServerStatementColumnEncryptionSetting stmtColEncSetting)
                              throws SQLServerException

Throws:
  `SQLServerException`

#### prepareStatement

    public PreparedStatement prepareStatement(String sql,
                                              int nType,
                                              int nConcur,
                                              int statementHoldability)
                                       throws SQLServerException

Specified by:
  `prepareStatement` in interface `Connection`
Throws:
  `SQLServerException`

#### prepareStatement

    public PreparedStatement prepareStatement(String sql,
                                              int nType,
                                              int nConcur,
                                              int statementHoldability,
                                              SQLServerStatementColumnEncryptionSetting stmtColEncSetting)
                                       throws SQLServerException

Throws:
  `SQLServerException`

#### prepareCall

    public CallableStatement prepareCall(String sql,
                                         int nType,
                                         int nConcur,
                                         int statementHoldability)
                                  throws SQLServerException

Specified by:
  `prepareCall` in interface `Connection`
Throws:
  `SQLServerException`

#### prepareCall

    public CallableStatement prepareCall(String sql,
                                         int nType,
                                         int nConcur,
                                         int statementHoldability,
                                         SQLServerStatementColumnEncryptionSetting stmtColEncSetiing)
                                  throws SQLServerException

Throws:
  `SQLServerException`

#### prepareStatement

    public PreparedStatement prepareStatement(String sql,
                                              int flag)
                                       throws SQLServerException

Specified by:
  `prepareStatement` in interface `Connection`
Throws:
  `SQLServerException`

#### prepareStatement

    public PreparedStatement prepareStatement(String sql,
                                              int flag,
                                              SQLServerStatementColumnEncryptionSetting stmtColEncSetting)
                                       throws SQLServerException

Throws:
  `SQLServerException`

#### prepareStatement

    public PreparedStatement prepareStatement(String sql,
                                              int[] columnIndexes)
                                       throws SQLServerException

Specified by:
  `prepareStatement` in interface `Connection`
Throws:
  `SQLServerException`

#### prepareStatement

    public PreparedStatement prepareStatement(String sql,
                                              int[] columnIndexes,
                                              SQLServerStatementColumnEncryptionSetting stmtColEncSetting)
                                       throws SQLServerException

Throws:
  `SQLServerException`

#### prepareStatement

    public PreparedStatement prepareStatement(String sql,
                                              String[] columnNames)
                                       throws SQLServerException

Specified by:
  `prepareStatement` in interface `Connection`
Throws:
  `SQLServerException`

#### prepareStatement

    public PreparedStatement prepareStatement(String sql,
                                              String[] columnNames,
                                              SQLServerStatementColumnEncryptionSetting stmtColEncSetting)
                                       throws SQLServerException

Throws:
  `SQLServerException`

#### releaseSavepoint

    public void releaseSavepoint(Savepoint savepoint)
                          throws SQLServerException

Specified by:
  `releaseSavepoint` in interface `Connection`
Throws:
  `SQLServerException`

#### setSavepoint

    public Savepoint setSavepoint(String sName)
                           throws SQLServerException

Specified by:
  `setSavepoint` in interface `Connection`
Throws:
  `SQLServerException`

#### setSavepoint

    public Savepoint setSavepoint()
                           throws SQLServerException

Specified by:
  `setSavepoint` in interface `Connection`
Throws:
  `SQLServerException`

#### rollback

    public void rollback(Savepoint s)
                  throws SQLServerException

Specified by:
  `rollback` in interface `Connection`
Throws:
  `SQLServerException`

#### getHoldability

    public int getHoldability()
                       throws SQLServerException

Specified by:
  `getHoldability` in interface `Connection`
Throws:
  `SQLServerException`

#### setHoldability

    public void setHoldability(int holdability)
                        throws SQLServerException

Specified by:
  `setHoldability` in interface `Connection`
Throws:
  `SQLServerException`

#### getNetworkTimeout

    public int getNetworkTimeout()
                          throws SQLException

Specified by:
  `getNetworkTimeout` in interface `Connection`
Throws:
  `SQLException`

#### setNetworkTimeout

    public void setNetworkTimeout(Executor executor,
                                  int timeout)
                           throws SQLException

Specified by:
  `setNetworkTimeout` in interface `Connection`
Throws:
  `SQLException`

#### getSchema

    public String getSchema()
                     throws SQLException

Specified by:
  `getSchema` in interface `Connection`
Throws:
  `SQLException`

#### setSchema

    public void setSchema(String schema)
                   throws SQLException

Specified by:
  `setSchema` in interface `Connection`
Throws:
  `SQLException`

#### setSendTimeAsDatetime

    public void setSendTimeAsDatetime(boolean sendTimeAsDateTimeValue)

#### createArrayOf

    public Array createArrayOf(String typeName,
                               Object[] elements)
                        throws SQLException

Specified by:
  `createArrayOf` in interface `Connection`
Throws:
  `SQLException`

#### createBlob

    public Blob createBlob()
                    throws SQLException

Specified by:
  `createBlob` in interface `Connection`
Throws:
  `SQLException`

#### createClob

    public Clob createClob()
                    throws SQLException

Specified by:
  `createClob` in interface `Connection`
Throws:
  `SQLException`

#### createNClob

    public NClob createNClob()
                      throws SQLException

Specified by:
  `createNClob` in interface `Connection`
Throws:
  `SQLException`

#### createSQLXML

    public SQLXML createSQLXML()
                        throws SQLException

Specified by:
  `createSQLXML` in interface `Connection`
Throws:
  `SQLException`

#### createStruct

    public Struct createStruct(String typeName,
                               Object[] attributes)
                        throws SQLException

Specified by:
  `createStruct` in interface `Connection`
Throws:
  `SQLException`

#### getClientInfo

    public Properties getClientInfo()
                             throws SQLException

Specified by:
  `getClientInfo` in interface `Connection`
Throws:
  `SQLException`

#### getClientInfo

    public String getClientInfo(String name)
                         throws SQLException

Specified by:
  `getClientInfo` in interface `Connection`
Throws:
  `SQLException`

#### setClientInfo

    public void setClientInfo(Properties properties)
                       throws SQLClientInfoException

Specified by:
  `setClientInfo` in interface `Connection`
Throws:
  `SQLClientInfoException`

#### setClientInfo

    public void setClientInfo(String name,
                              String value)
                       throws SQLClientInfoException

Specified by:
  `setClientInfo` in interface `Connection`
Throws:
  `SQLClientInfoException`

#### isValid

    public boolean isValid(int timeout)
                    throws SQLException

Determine whether the connection is still valid. The driver shall submit a query on the connection or use some other mechanism that positively verifies the connection is still valid when this method is called. The query submitted by the driver to validate the connection shall be executed in the context of the current transaction.

Specified by:
  `isValid` in interface `Connection`
Parameters:
  `timeout` - 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...
Returns:
  true if the connection has not been closed and is still valid.
Throws:
  `SQLException` - if the value supplied for the timeout is less than 0.

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

#### setColumnEncryptionKeyCacheTtl

    public static void setColumnEncryptionKeyCacheTtl(int columnEncryptionKeyCacheTTL,
                                                      TimeUnit unit)
                                               throws SQLServerException

Throws:
  `SQLServerException`