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_SNAPSHOT
TRANSACTION_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 |
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.
|
int |
getHoldability() |
DatabaseMetaData |
getMetaData() |
int |
getNetworkTimeout() |
String |
getSchema() |
boolean |
getSendTimeAsDatetime()
Checks the sendTimeAsDatetime property.
|
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 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 |
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 |
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 ISQLServerConnection
SQLServerException
- when an error occurspublic String toString()
public Statement createStatement() throws SQLServerException
createStatement
in interface Connection
SQLServerException
public PreparedStatement prepareStatement(String sql) throws SQLServerException
prepareStatement
in interface Connection
SQLServerException
public CallableStatement prepareCall(String sql) throws SQLServerException
prepareCall
in interface Connection
SQLServerException
public String nativeSQL(String sql) throws SQLServerException
nativeSQL
in interface Connection
SQLServerException
public void setAutoCommit(boolean newAutoCommitMode) throws SQLServerException
setAutoCommit
in interface Connection
SQLServerException
public boolean getAutoCommit() throws SQLServerException
getAutoCommit
in interface Connection
SQLServerException
public void commit() throws SQLServerException
commit
in interface Connection
SQLServerException
- if no transaction exists.public void rollback() throws SQLServerException
rollback
in interface Connection
SQLServerException
- if no transaction exists or if the connection is in auto-commit mode.public void abort(Executor executor) throws SQLException
abort
in interface Connection
SQLException
public void close() throws SQLServerException
close
in interface AutoCloseable
close
in interface Connection
SQLServerException
public boolean isClosed() throws SQLServerException
isClosed
in interface Connection
SQLServerException
public DatabaseMetaData getMetaData() throws SQLServerException
getMetaData
in interface Connection
SQLServerException
public void setReadOnly(boolean readOnly) throws SQLServerException
setReadOnly
in interface Connection
SQLServerException
public boolean isReadOnly() throws SQLServerException
isReadOnly
in interface Connection
SQLServerException
public void setCatalog(String catalog) throws SQLServerException
setCatalog
in interface Connection
SQLServerException
public String getCatalog() throws SQLServerException
getCatalog
in interface Connection
SQLServerException
public void setTransactionIsolation(int level) throws SQLServerException
setTransactionIsolation
in interface Connection
SQLServerException
public int getTransactionIsolation() throws SQLServerException
getTransactionIsolation
in interface Connection
SQLServerException
public SQLWarning getWarnings() throws SQLServerException
getWarnings
in interface Connection
SQLServerException
public void clearWarnings() throws SQLServerException
clearWarnings
in interface Connection
SQLServerException
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLServerException
createStatement
in interface Connection
SQLServerException
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLServerException
prepareStatement
in interface Connection
SQLServerException
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLServerException
prepareCall
in interface Connection
SQLServerException
public void setTypeMap(Map<String,Class<?>> map) throws SQLServerException
setTypeMap
in interface Connection
SQLServerException
public Map<String,Class<?>> getTypeMap() throws SQLServerException
getTypeMap
in interface Connection
SQLServerException
public Statement createStatement(int nType, int nConcur, int resultSetHoldability) throws SQLServerException
createStatement
in interface Connection
SQLServerException
public Statement createStatement(int nType, int nConcur, int resultSetHoldability, SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException
SQLServerException
public PreparedStatement prepareStatement(String sql, int nType, int nConcur, int resultSetHoldability) throws SQLServerException
prepareStatement
in interface Connection
SQLServerException
public 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_SENSITIVE
nConcur
- one of the following ResultSet
constants: ResultSet.CONCUR_READ_ONLY
or
ResultSet.CONCUR_UPDATABLE
resultSetHoldability
- one of the following ResultSet
constants: ResultSet.HOLD_CURSORS_OVER_COMMIT
or
ResultSet.CLOSE_CURSORS_AT_COMMIT
stmtColEncSetting
- 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 Connection
SQLServerException
public CallableStatement prepareCall(String sql, int nType, int nConcur, int resultSetHoldability, SQLServerStatementColumnEncryptionSetting stmtColEncSetiing) throws SQLServerException
SQLServerException
public PreparedStatement prepareStatement(String sql, int flag) throws SQLServerException
prepareStatement
in interface Connection
SQLServerException
public 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_KEYS
stmtColEncSetting
- 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 Connection
SQLServerException
public 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 Connection
SQLServerException
public 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 Connection
SQLServerException
public Savepoint setSavepoint(String sName) throws SQLServerException
setSavepoint
in interface Connection
SQLServerException
public Savepoint setSavepoint() throws SQLServerException
setSavepoint
in interface Connection
SQLServerException
public void rollback(Savepoint s) throws SQLServerException
rollback
in interface Connection
SQLServerException
public int getHoldability() throws SQLServerException
getHoldability
in interface Connection
SQLServerException
public void setHoldability(int holdability) throws SQLServerException
setHoldability
in interface Connection
SQLServerException
public int getNetworkTimeout() throws SQLException
getNetworkTimeout
in interface Connection
SQLException
public void setNetworkTimeout(Executor executor, int timeout) throws SQLException
setNetworkTimeout
in interface Connection
SQLException
public String getSchema() throws SQLException
getSchema
in interface Connection
SQLException
public void setSchema(String schema) throws SQLException
setSchema
in interface Connection
SQLException
public 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 Connection
SQLException
public Blob createBlob() throws SQLException
createBlob
in interface Connection
SQLException
public Clob createClob() throws SQLException
createClob
in interface Connection
SQLException
public NClob createNClob() throws SQLException
createNClob
in interface Connection
SQLException
public SQLXML createSQLXML() throws SQLException
createSQLXML
in interface Connection
SQLException
public Struct createStruct(String typeName, Object[] attributes) throws SQLException
createStruct
in interface Connection
SQLException
public Properties getClientInfo() throws SQLException
getClientInfo
in interface Connection
SQLException
public String getClientInfo(String name) throws SQLException
getClientInfo
in interface Connection
SQLException
public void setClientInfo(Properties properties) throws SQLClientInfoException
setClientInfo
in interface Connection
SQLClientInfoException
public void setClientInfo(String name, String value) throws SQLClientInfoException
setClientInfo
in interface Connection
SQLClientInfoException
public boolean isValid(int timeout) throws SQLException
isValid
in interface Connection
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...SQLException
- if the value supplied for the timeout is less than 0.public boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor
in interface Wrapper
SQLException
public <T> T unwrap(Class<T> iface) throws SQLException
unwrap
in interface Wrapper
SQLException
public static void setColumnEncryptionKeyCacheTtl(int columnEncryptionKeyCacheTTL, TimeUnit unit) throws SQLServerException
columnEncryptionKeyCacheTTL
- The timeunit in secondsunit
- The Timeunit.SQLServerException
- when an error occursCopyright © 2017 Microsoft Corporation. All rights reserved.