Class SQLServerConnection
- All Implemented Interfaces:
ISQLServerConnection,java.io.Serializable,java.lang.AutoCloseable,java.sql.Connection,java.sql.Wrapper
- Direct Known Subclasses:
SQLServerConnection43
public class SQLServerConnection extends java.lang.Object implements ISQLServerConnection, java.io.Serializable
- See Also:
- Serialized Form
-
Field Summary
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLEFields inherited from interface com.microsoft.sqlserver.jdbc.ISQLServerConnection
TRANSACTION_SNAPSHOT -
Method Summary
Modifier and Type Method Description voidabort(java.util.concurrent.Executor executor)protected voidbeginRequestInternal()voidclearWarnings()voidclose()voidcloseUnreferencedPreparedStatementHandles()Forces the un-prepare requests for any outstanding discarded prepared statements to be executed.voidcommit()java.sql.ArraycreateArrayOf(java.lang.String typeName, java.lang.Object[] elements)java.sql.BlobcreateBlob()java.sql.ClobcreateClob()java.sql.NClobcreateNClob()java.sql.SQLXMLcreateSQLXML()java.sql.StatementcreateStatement()java.sql.StatementcreateStatement(int resultSetType, int resultSetConcurrency)java.sql.StatementcreateStatement(int nType, int nConcur, int resultSetHoldability)java.sql.StatementcreateStatement(int nType, int nConcur, int resultSetHoldability, SQLServerStatementColumnEncryptionSetting stmtColEncSetting)Creates aStatementobject that will generateResultSetobjects with the given type, concurrency, and holdability.java.sql.StructcreateStruct(java.lang.String typeName, java.lang.Object[] attributes)protected voidendRequestInternal()booleangetAutoCommit()java.lang.StringgetCatalog()java.util.UUIDgetClientConnectionId()Returns the connection ID of the most recent connection attempt, regardless of whether the attempt succeeded or failed.java.util.PropertiesgetClientInfo()java.lang.StringgetClientInfo(java.lang.String name)static java.util.Map<java.lang.String,java.util.List<java.lang.String>>getColumnEncryptionTrustedMasterKeyPaths()Returns the Trusted Master Key Paths.booleangetDisableStatementPooling()Returns the value whether statement pooling is disabled.intgetDiscardedServerPreparedStatementCount()Returns the number of currently outstanding prepared statement un-prepare actions.booleangetEnablePrepareOnFirstPreparedStatementCall()Returns the behavior for a specific connection instance.intgetHoldability()java.sql.DatabaseMetaDatagetMetaData()intgetNetworkTimeout()java.lang.StringgetSchema()booleangetSendTimeAsDatetime()Returns the value of the sendTimeAsDatetime property.intgetServerPreparedStatementDiscardThreshold()Returns the behavior for a specific connection instance.intgetStatementHandleCacheEntryCount()Returns the current number of pooled prepared statement handles.intgetStatementPoolingCacheSize()Returns the size of the prepared statement cache for this connection.intgetTransactionIsolation()java.util.Map<java.lang.String,java.lang.Class<?>>getTypeMap()booleangetUseBulkCopyForBatchInsert()Returns the useBulkCopyForBatchInsert value.booleangetUseFmtOnly()Returns the current flag value for useFmtOnly.java.sql.SQLWarninggetWarnings()booleanisClosed()booleanisReadOnly()booleanisStatementPoolingEnabled()Returns whether statement pooling is enabled or not for this connection.booleanisValid(int timeout)Determine whether the connection is still valid.booleanisWrapperFor(java.lang.Class<?> iface)java.lang.StringnativeSQL(java.lang.String sql)protected booleanneedsReconnect()Returns if Federated Authentication is in use or is about to expire soonjava.sql.CallableStatementprepareCall(java.lang.String sql)java.sql.CallableStatementprepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)java.sql.CallableStatementprepareCall(java.lang.String sql, int nType, int nConcur, int resultSetHoldability)java.sql.CallableStatementprepareCall(java.lang.String sql, int nType, int nConcur, int resultSetHoldability, SQLServerStatementColumnEncryptionSetting stmtColEncSetiing)Creates aCallableStatementobject that will generateResultSetobjects with the given type and concurrency.java.sql.PreparedStatementprepareStatement(java.lang.String sql)java.sql.PreparedStatementprepareStatement(java.lang.String sql, int flag)java.sql.PreparedStatementprepareStatement(java.lang.String sql, int[] columnIndexes)java.sql.PreparedStatementprepareStatement(java.lang.String sql, int[] columnIndexes, SQLServerStatementColumnEncryptionSetting stmtColEncSetting)Creates a defaultPreparedStatementobject capable of returning the auto-generated keys designated by the given array.java.sql.PreparedStatementprepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)java.sql.PreparedStatementprepareStatement(java.lang.String sql, int nType, int nConcur, int resultSetHoldability)java.sql.PreparedStatementprepareStatement(java.lang.String sql, int nType, int nConcur, int resultSetHoldability, SQLServerStatementColumnEncryptionSetting stmtColEncSetting)Creates aPreparedStatementobject that will generateResultSetobjects with the given type, concurrency, and holdability.java.sql.PreparedStatementprepareStatement(java.lang.String sql, int flag, SQLServerStatementColumnEncryptionSetting stmtColEncSetting)Creates a defaultPreparedStatementobject that has the capability to retrieve auto-generated keys.java.sql.PreparedStatementprepareStatement(java.lang.String sql, java.lang.String[] columnNames)java.sql.PreparedStatementprepareStatement(java.lang.String sql, java.lang.String[] columnNames, SQLServerStatementColumnEncryptionSetting stmtColEncSetting)Creates a defaultPreparedStatementobject capable of returning the auto-generated keys designated by the given array.static voidregisterColumnEncryptionKeyStoreProviders(java.util.Map<java.lang.String,SQLServerColumnEncryptionKeyStoreProvider> clientKeyStoreProviders)Registers key store providers in the globalCustomColumnEncryptionKeyStoreProviders.voidreleaseSavepoint(java.sql.Savepoint savepoint)static voidremoveColumnEncryptionTrustedMasterKeyPaths(java.lang.String server)Removes the trusted Master key Path from the columnEncryptionTrustedMasterKeyPaths.voidrollback()voidrollback(java.sql.Savepoint s)voidsetAutoCommit(boolean newAutoCommitMode)voidsetCatalog(java.lang.String catalog)voidsetClientInfo(java.lang.String name, java.lang.String value)voidsetClientInfo(java.util.Properties properties)static voidsetColumnEncryptionKeyCacheTtl(int columnEncryptionKeyCacheTTL, java.util.concurrent.TimeUnit unit)Sets time-to-live for column encryption key entries in the column encryption key cache for the Always Encrypted feature.static voidsetColumnEncryptionTrustedMasterKeyPaths(java.util.Map<java.lang.String,java.util.List<java.lang.String>> trustedKeyPaths)Sets Trusted Master Key Paths in the columnEncryptionTrustedMasterKeyPaths.voidsetDisableStatementPooling(boolean value)Sets the value to Disable/enable statement pooling.voidsetEnablePrepareOnFirstPreparedStatementCall(boolean value)Sets the behavior for a specific connection instance.voidsetHoldability(int holdability)voidsetNetworkTimeout(java.util.concurrent.Executor executor, int timeout)voidsetReadOnly(boolean readOnly)java.sql.SavepointsetSavepoint()java.sql.SavepointsetSavepoint(java.lang.String sName)voidsetSchema(java.lang.String schema)voidsetSendTimeAsDatetime(boolean sendTimeAsDateTimeValue)Sets the value of the sendTimeAsDatetime connection property.voidsetServerPreparedStatementDiscardThreshold(int value)Sets the behavior for a specific connection instance.voidsetStatementPoolingCacheSize(int value)Sets the size of the prepared statement cache for this connection.voidsetTransactionIsolation(int level)voidsetTypeMap(java.util.Map<java.lang.String,java.lang.Class<?>> map)voidsetUseBulkCopyForBatchInsert(boolean useBulkCopyForBatchInsert)Specifies the flag for using Bulk Copy API for batch insert operations.voidsetUseFmtOnly(boolean useFmtOnly)Specifies the flag to use FMTONLY for parameter metadata queries.java.lang.StringtoString()Provides a helper function to return an ID string suitable for tracing.static voidunregisterColumnEncryptionKeyStoreProviders()Unregisters all the custom key store providers from the globalCustomColumnEncryptionKeyStoreProviders by clearing the map and setting it to null.<T> Tunwrap(java.lang.Class<T> iface)static voidupdateColumnEncryptionTrustedMasterKeyPaths(java.lang.String server, java.util.List<java.lang.String> trustedKeyPaths)Updates the columnEncryptionTrustedMasterKeyPaths with the new Server and trustedKeyPaths.
-
Method Details
-
getUseBulkCopyForBatchInsert
public boolean getUseBulkCopyForBatchInsert()Returns the useBulkCopyForBatchInsert value.- Returns:
- flag for using Bulk Copy API for batch insert operations.
-
setUseBulkCopyForBatchInsert
public void setUseBulkCopyForBatchInsert(boolean useBulkCopyForBatchInsert)Specifies the flag for using Bulk Copy API for batch insert operations.- Parameters:
useBulkCopyForBatchInsert- boolean value for useBulkCopyForBatchInsert.
-
getSendTimeAsDatetime
public final boolean getSendTimeAsDatetime()Description copied from interface:ISQLServerConnectionReturns the value of the sendTimeAsDatetime property.- Specified by:
getSendTimeAsDatetimein interfaceISQLServerConnection- Returns:
- boolean value of sendTimeAsDatetime
-
registerColumnEncryptionKeyStoreProviders
public static void registerColumnEncryptionKeyStoreProviders(java.util.Map<java.lang.String,SQLServerColumnEncryptionKeyStoreProvider> clientKeyStoreProviders) throws SQLServerExceptionRegisters key store providers in the globalCustomColumnEncryptionKeyStoreProviders.- Parameters:
clientKeyStoreProviders- a map containing the store providers information.- Throws:
SQLServerException- when an error occurs
-
unregisterColumnEncryptionKeyStoreProviders
public static void unregisterColumnEncryptionKeyStoreProviders()Unregisters all the custom key store providers from the globalCustomColumnEncryptionKeyStoreProviders by clearing the map and setting it to null. -
setColumnEncryptionTrustedMasterKeyPaths
public static void setColumnEncryptionTrustedMasterKeyPaths(java.util.Map<java.lang.String,java.util.List<java.lang.String>> trustedKeyPaths)Sets Trusted Master Key Paths in the columnEncryptionTrustedMasterKeyPaths.- Parameters:
trustedKeyPaths- all master key paths that are trusted
-
updateColumnEncryptionTrustedMasterKeyPaths
public static void updateColumnEncryptionTrustedMasterKeyPaths(java.lang.String server, java.util.List<java.lang.String> trustedKeyPaths)Updates the columnEncryptionTrustedMasterKeyPaths with the new Server and trustedKeyPaths.- Parameters:
server- String server nametrustedKeyPaths- all master key paths that are trusted
-
removeColumnEncryptionTrustedMasterKeyPaths
public static void removeColumnEncryptionTrustedMasterKeyPaths(java.lang.String server)Removes the trusted Master key Path from the columnEncryptionTrustedMasterKeyPaths.- Parameters:
server- String server name
-
getColumnEncryptionTrustedMasterKeyPaths
public static java.util.Map<java.lang.String,java.util.List<java.lang.String>> getColumnEncryptionTrustedMasterKeyPaths()Returns the Trusted Master Key Paths.- Returns:
- columnEncryptionTrustedMasterKeyPaths.
-
getClientConnectionId
Description copied from interface:ISQLServerConnectionReturns the connection ID of the most recent connection attempt, regardless of whether the attempt succeeded or failed.- Specified by:
getClientConnectionIdin interfaceISQLServerConnection- Returns:
- 16-byte GUID representing the connection ID of the most recent connection attempt. Or, NULL if there is a failure after the connection request is initiated and the pre-login handshake.
- Throws:
SQLServerException- If any errors occur.
-
toString
public java.lang.String toString()Provides a helper function to return an ID string suitable for tracing.- Overrides:
toStringin classjava.lang.Object
-
needsReconnect
protected boolean needsReconnect()Returns if Federated Authentication is in use or is about to expire soon- Returns:
- true/false
-
createStatement
- Specified by:
createStatementin interfacejava.sql.Connection- Throws:
SQLServerException
-
prepareStatement
- Specified by:
prepareStatementin interfacejava.sql.Connection- Throws:
SQLServerException
-
prepareCall
- Specified by:
prepareCallin interfacejava.sql.Connection- Throws:
SQLServerException
-
nativeSQL
- Specified by:
nativeSQLin interfacejava.sql.Connection- Throws:
SQLServerException
-
setAutoCommit
- Specified by:
setAutoCommitin interfacejava.sql.Connection- Throws:
SQLServerException
-
getAutoCommit
- Specified by:
getAutoCommitin interfacejava.sql.Connection- Throws:
SQLServerException
-
commit
- Specified by:
commitin interfacejava.sql.Connection- Throws:
SQLServerException
-
rollback
- Specified by:
rollbackin interfacejava.sql.Connection- Throws:
SQLServerException
-
abort
public void abort(java.util.concurrent.Executor executor) throws java.sql.SQLException- Specified by:
abortin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
close
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.sql.Connection- Throws:
SQLServerException
-
isClosed
- Specified by:
isClosedin interfacejava.sql.Connection- Throws:
SQLServerException
-
getMetaData
- Specified by:
getMetaDatain interfacejava.sql.Connection- Throws:
SQLServerException
-
setReadOnly
- Specified by:
setReadOnlyin interfacejava.sql.Connection- Throws:
SQLServerException
-
isReadOnly
- Specified by:
isReadOnlyin interfacejava.sql.Connection- Throws:
SQLServerException
-
setCatalog
- Specified by:
setCatalogin interfacejava.sql.Connection- Throws:
SQLServerException
-
getCatalog
- Specified by:
getCatalogin interfacejava.sql.Connection- Throws:
SQLServerException
-
setTransactionIsolation
- Specified by:
setTransactionIsolationin interfacejava.sql.Connection- Throws:
SQLServerException
-
getTransactionIsolation
- Specified by:
getTransactionIsolationin interfacejava.sql.Connection- Throws:
SQLServerException
-
getWarnings
- Specified by:
getWarningsin interfacejava.sql.Connection- Throws:
SQLServerException
-
clearWarnings
- Specified by:
clearWarningsin interfacejava.sql.Connection- Throws:
SQLServerException
-
createStatement
public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLServerException- Specified by:
createStatementin interfacejava.sql.Connection- Throws:
SQLServerException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws SQLServerException- Specified by:
prepareStatementin interfacejava.sql.Connection- Throws:
SQLServerException
-
prepareCall
public java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws SQLServerException- Specified by:
prepareCallin interfacejava.sql.Connection- Throws:
SQLServerException
-
setTypeMap
public void setTypeMap(java.util.Map<java.lang.String,java.lang.Class<?>> map) throws java.sql.SQLException- Specified by:
setTypeMapin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getTypeMap
- Specified by:
getTypeMapin interfacejava.sql.Connection- Throws:
SQLServerException
-
createStatement
public java.sql.Statement createStatement(int nType, int nConcur, int resultSetHoldability) throws SQLServerException- Specified by:
createStatementin interfacejava.sql.Connection- Throws:
SQLServerException
-
createStatement
public java.sql.Statement createStatement(int nType, int nConcur, int resultSetHoldability, SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerExceptionDescription copied from interface:ISQLServerConnectionCreates aStatementobject that will generateResultSetobjects with the given type, concurrency, and holdability. This method is the same as thecreateStatementmethod above, but it allows the default result set type, concurrency, and holdability to be overridden.- Specified by:
createStatementin interfaceISQLServerConnection- Parameters:
nType- one of the followingResultSetconstants:ResultSet.TYPE_FORWARD_ONLY,ResultSet.TYPE_SCROLL_INSENSITIVE, orResultSet.TYPE_SCROLL_SENSITIVEnConcur- one of the followingResultSetconstants:ResultSet.CONCUR_READ_ONLYorResultSet.CONCUR_UPDATABLEresultSetHoldability- one of the followingResultSetconstants:ResultSet.HOLD_CURSORS_OVER_COMMITorResultSet.CLOSE_CURSORS_AT_COMMITstmtColEncSetting- Specifies how data will be sent and received when reading and writing encrypted columns.- Returns:
- a new
Statementobject that will generateResultSetobjects with the given type, concurrency, and holdability - Throws:
SQLServerException- if a database access error occurs, this method is called on a closed connection or the given parameters are notResultSetconstants indicating type, concurrency, and holdability
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int nType, int nConcur, int resultSetHoldability) throws SQLServerException- Specified by:
prepareStatementin interfacejava.sql.Connection- Throws:
SQLServerException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int nType, int nConcur, int resultSetHoldability, SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerExceptionDescription copied from interface:ISQLServerConnectionCreates aPreparedStatementobject that will generateResultSetobjects with the given type, concurrency, and holdability.This method is the same as the
prepareStatementmethod above, but it allows the default result set type, concurrency, and holdability to be overridden.- Specified by:
prepareStatementin interfaceISQLServerConnection- Parameters:
sql- aStringobject that is the SQL statement to be sent to the database; may contain one or more '?' IN parametersnType- one of the followingResultSetconstants:ResultSet.TYPE_FORWARD_ONLY,ResultSet.TYPE_SCROLL_INSENSITIVE, orResultSet.TYPE_SCROLL_SENSITIVEnConcur- one of the followingResultSetconstants:ResultSet.CONCUR_READ_ONLYorResultSet.CONCUR_UPDATABLEresultSetHoldability- one of the followingResultSetconstants:ResultSet.HOLD_CURSORS_OVER_COMMITorResultSet.CLOSE_CURSORS_AT_COMMITstmtColEncSetting- Specifies how data will be sent and received when reading and writing encrypted columns.- Returns:
- a new
PreparedStatementobject, containing the pre-compiled SQL statement, that will generateResultSetobjects with the given type, concurrency, and holdability - Throws:
SQLServerException- if a database access error occurs, this method is called on a closed connection or the given parameters are notResultSetconstants indicating type, concurrency, and holdability
-
prepareCall
public java.sql.CallableStatement prepareCall(java.lang.String sql, int nType, int nConcur, int resultSetHoldability) throws SQLServerException- Specified by:
prepareCallin interfacejava.sql.Connection- Throws:
SQLServerException
-
prepareCall
public java.sql.CallableStatement prepareCall(java.lang.String sql, int nType, int nConcur, int resultSetHoldability, SQLServerStatementColumnEncryptionSetting stmtColEncSetiing) throws SQLServerExceptionDescription copied from interface:ISQLServerConnectionCreates aCallableStatementobject that will generateResultSetobjects with the given type and concurrency. This method is the same as theprepareCallmethod above, but it allows the default result set type, result set concurrency type and holdability to be overridden.- Specified by:
prepareCallin interfaceISQLServerConnection- Parameters:
sql- aStringobject that is the SQL statement to be sent to the database; may contain on or more '?' parametersnType- one of the followingResultSetconstants:ResultSet.TYPE_FORWARD_ONLY,ResultSet.TYPE_SCROLL_INSENSITIVE, orResultSet.TYPE_SCROLL_SENSITIVEnConcur- one of the followingResultSetconstants:ResultSet.CONCUR_READ_ONLYorResultSet.CONCUR_UPDATABLEresultSetHoldability- one of the followingResultSetconstants:ResultSet.HOLD_CURSORS_OVER_COMMITorResultSet.CLOSE_CURSORS_AT_COMMITstmtColEncSetiing- Specifies how data will be sent and received when reading and writing encrypted columns.- Returns:
- a new
CallableStatementobject, containing the pre-compiled SQL statement, that will generateResultSetobjects with the given type, concurrency, and holdability - Throws:
SQLServerException- if a database access error occurs, this method is called on a closed connection or the given parameters are notResultSetconstants indicating type, concurrency, and holdability
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int flag) throws SQLServerException- Specified by:
prepareStatementin interfacejava.sql.Connection- Throws:
SQLServerException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int flag, SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerExceptionDescription copied from interface:ISQLServerConnectionCreates a defaultPreparedStatementobject 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 anINSERTstatement, 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
prepareStatementwill 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 thePreparedStatementobject is executed. This has no direct effect on users; however, it does affect which methods throw certain SQLExceptions.Result sets created using the returned
PreparedStatementobject will by default be typeTYPE_FORWARD_ONLYand have a concurrency level ofCONCUR_READ_ONLY. The holdability of the created result sets can be determined by callingConnection.getHoldability().- Specified by:
prepareStatementin interfaceISQLServerConnection- Parameters:
sql- an SQL statement that may contain one or more '?' IN parameter placeholdersflag- a flag indicating whether auto-generated keys should be returned; one ofStatement.RETURN_GENERATED_KEYSorStatement.NO_GENERATED_KEYSstmtColEncSetting- Specifies how data will be sent and received when reading and writing encrypted columns.- Returns:
- a new
PreparedStatementobject, containing the pre-compiled SQL statement, that will have the capability of returning auto-generated keys - Throws:
SQLServerException- if a database access error occurs, this method is called on a closed connection or the given parameter is not aStatementconstant indicating whether auto-generated keys should be returned
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int[] columnIndexes) throws SQLServerException- Specified by:
prepareStatementin interfacejava.sql.Connection- Throws:
SQLServerException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int[] columnIndexes, SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerExceptionDescription copied from interface:ISQLServerConnectionCreates a defaultPreparedStatementobject 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 anINSERTstatement, 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
PreparedStatementobject. 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
prepareStatementwill 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 thePreparedStatementobject is executed. This has no direct effect on users; however, it does affect which methods throw certain SQLExceptions.Result sets created using the returned
PreparedStatementobject will by default be typeTYPE_FORWARD_ONLYand have a concurrency level ofCONCUR_READ_ONLY. The holdability of the created result sets can be determined by callingConnection.getHoldability().- Specified by:
prepareStatementin interfaceISQLServerConnection- Parameters:
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.- Returns:
- a new
PreparedStatementobject, containing the pre-compiled statement, that is capable of returning the auto-generated keys designated by the given array of column indexes - Throws:
SQLServerException- if a database access error occurs or this method is called on a closed connection
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.String[] columnNames) throws SQLServerException- Specified by:
prepareStatementin interfacejava.sql.Connection- Throws:
SQLServerException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.String[] columnNames, SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerExceptionDescription copied from interface:ISQLServerConnectionCreates a defaultPreparedStatementobject 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 anINSERTstatement, 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
PreparedStatementobject. 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
prepareStatementwill 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 thePreparedStatementobject is executed. This has no direct effect on users; however, it does affect which methods throw certain SQLExceptions.Result sets created using the returned
PreparedStatementobject will by default be typeTYPE_FORWARD_ONLYand have a concurrency level ofCONCUR_READ_ONLY. The holdability of the created result sets can be determined by callingConnection.getHoldability().- Specified by:
prepareStatementin interfaceISQLServerConnection- Parameters:
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.- Returns:
- a new
PreparedStatementobject, containing the pre-compiled statement, that is capable of returning the auto-generated keys designated by the given array of column names - Throws:
SQLServerException- if a database access error occurs or this method is called on a closed connection
-
releaseSavepoint
public void releaseSavepoint(java.sql.Savepoint savepoint) throws java.sql.SQLException- Specified by:
releaseSavepointin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setSavepoint
- Specified by:
setSavepointin interfacejava.sql.Connection- Throws:
SQLServerException
-
setSavepoint
- Specified by:
setSavepointin interfacejava.sql.Connection- Throws:
SQLServerException
-
rollback
- Specified by:
rollbackin interfacejava.sql.Connection- Throws:
SQLServerException
-
getHoldability
- Specified by:
getHoldabilityin interfacejava.sql.Connection- Throws:
SQLServerException
-
setHoldability
- Specified by:
setHoldabilityin interfacejava.sql.Connection- Throws:
SQLServerException
-
getNetworkTimeout
public int getNetworkTimeout() throws java.sql.SQLException- Specified by:
getNetworkTimeoutin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setNetworkTimeout
public void setNetworkTimeout(java.util.concurrent.Executor executor, int timeout) throws java.sql.SQLException- Specified by:
setNetworkTimeoutin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getSchema
public java.lang.String getSchema() throws java.sql.SQLException- Specified by:
getSchemain interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setSchema
public void setSchema(java.lang.String schema) throws java.sql.SQLException- Specified by:
setSchemain interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setSendTimeAsDatetime
public void setSendTimeAsDatetime(boolean sendTimeAsDateTimeValue)Description copied from interface:ISQLServerConnectionSets the value of the sendTimeAsDatetime connection property. When true, java.sql.Time values will be sent to the server as SQL Serverdatetime values. When false, java.sql.Time values will be sent to the server as SQL Servertime values. sendTimeAsDatetime can also be modified programmatically with SQLServerDataSource.setSendTimeAsDatetime. The default value for this property may change in a future release.- Specified by:
setSendTimeAsDatetimein interfaceISQLServerConnection- Parameters:
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.
-
setUseFmtOnly
public void setUseFmtOnly(boolean useFmtOnly)Description copied from interface:ISQLServerConnectionSpecifies the flag to use FMTONLY for parameter metadata queries.- Specified by:
setUseFmtOnlyin interfaceISQLServerConnection- Parameters:
useFmtOnly- boolean value for 'useFmtOnly'.
-
getUseFmtOnly
public final boolean getUseFmtOnly()Description copied from interface:ISQLServerConnectionReturns the current flag value for useFmtOnly.- Specified by:
getUseFmtOnlyin interfaceISQLServerConnection- Returns:
- 'useFmtOnly' property value.
-
createArrayOf
public java.sql.Array createArrayOf(java.lang.String typeName, java.lang.Object[] elements) throws java.sql.SQLException- Specified by:
createArrayOfin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
createBlob
public java.sql.Blob createBlob() throws java.sql.SQLException- Specified by:
createBlobin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
createClob
public java.sql.Clob createClob() throws java.sql.SQLException- Specified by:
createClobin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
createNClob
public java.sql.NClob createNClob() throws java.sql.SQLException- Specified by:
createNClobin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
createSQLXML
public java.sql.SQLXML createSQLXML() throws java.sql.SQLException- Specified by:
createSQLXMLin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
createStruct
public java.sql.Struct createStruct(java.lang.String typeName, java.lang.Object[] attributes) throws java.sql.SQLException- Specified by:
createStructin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getClientInfo
public java.util.Properties getClientInfo() throws java.sql.SQLException- Specified by:
getClientInfoin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
getClientInfo
public java.lang.String getClientInfo(java.lang.String name) throws java.sql.SQLException- Specified by:
getClientInfoin interfacejava.sql.Connection- Throws:
java.sql.SQLException
-
setClientInfo
public void setClientInfo(java.util.Properties properties) throws java.sql.SQLClientInfoException- Specified by:
setClientInfoin interfacejava.sql.Connection- Throws:
java.sql.SQLClientInfoException
-
setClientInfo
public void setClientInfo(java.lang.String name, java.lang.String value) throws java.sql.SQLClientInfoException- Specified by:
setClientInfoin interfacejava.sql.Connection- Throws:
java.sql.SQLClientInfoException
-
isValid
public boolean isValid(int timeout) throws java.sql.SQLExceptionDetermine 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:
isValidin interfacejava.sql.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:
java.sql.SQLException- if the value supplied for the timeout is less than 0.
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException- Specified by:
isWrapperForin interfacejava.sql.Wrapper- Throws:
java.sql.SQLException
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException- Specified by:
unwrapin interfacejava.sql.Wrapper- Throws:
java.sql.SQLException
-
beginRequestInternal
protected void beginRequestInternal() throws java.sql.SQLException- Throws:
java.sql.SQLException
-
endRequestInternal
protected void endRequestInternal() throws java.sql.SQLException- Throws:
java.sql.SQLException
-
setColumnEncryptionKeyCacheTtl
public static void setColumnEncryptionKeyCacheTtl(int columnEncryptionKeyCacheTTL, java.util.concurrent.TimeUnit unit) throws SQLServerExceptionSets time-to-live for column encryption key entries in the column encryption key cache for the Always Encrypted feature. The default value is 2 hours. This variable holds the value in seconds.- Parameters:
columnEncryptionKeyCacheTTL- The timeunit in secondsunit- The Timeunit.- Throws:
SQLServerException- when an error occurs
-
getDiscardedServerPreparedStatementCount
public int getDiscardedServerPreparedStatementCount()Description copied from interface:ISQLServerConnectionReturns the number of currently outstanding prepared statement un-prepare actions.- Specified by:
getDiscardedServerPreparedStatementCountin interfaceISQLServerConnection- Returns:
- Returns the current value per the description.
-
closeUnreferencedPreparedStatementHandles
public void closeUnreferencedPreparedStatementHandles()Description copied from interface:ISQLServerConnectionForces the un-prepare requests for any outstanding discarded prepared statements to be executed.- Specified by:
closeUnreferencedPreparedStatementHandlesin interfaceISQLServerConnection
-
getEnablePrepareOnFirstPreparedStatementCall
public boolean getEnablePrepareOnFirstPreparedStatementCall()Description copied from interface:ISQLServerConnectionReturns the behavior for a specific connection instance. If false the first execution will call sp_executesql and not prepare a statement, once the second execution happens it will call sp_prepexec and actually setup a prepared statement handle. Following executions will call sp_execute. This relieves the need for sp_unprepare on prepared statement close if the statement is only executed once. The default for this option can be changed by calling setDefaultEnablePrepareOnFirstPreparedStatementCall().- Specified by:
getEnablePrepareOnFirstPreparedStatementCallin interfaceISQLServerConnection- Returns:
- Returns the current setting per the description.
-
setEnablePrepareOnFirstPreparedStatementCall
public void setEnablePrepareOnFirstPreparedStatementCall(boolean value)Description copied from interface:ISQLServerConnectionSets the behavior for a specific connection instance. If value is false the first execution will call sp_executesql and not prepare a statement, once the second execution happens it will call sp_prepexec and actually setup a prepared statement handle. Following executions will call sp_execute. This relieves the need for sp_unprepare on prepared statement close if the statement is only executed once.- Specified by:
setEnablePrepareOnFirstPreparedStatementCallin interfaceISQLServerConnection- Parameters:
value- Changes the setting per the description.
-
getServerPreparedStatementDiscardThreshold
public int getServerPreparedStatementDiscardThreshold()Description copied from interface:ISQLServerConnectionReturns the behavior for a specific connection instance. This setting controls how many outstanding prepared statement discard actions (sp_unprepare) can be outstanding per connection before a call to clean-up the outstanding handles on the server is executed. If the setting is <= 1, unprepare actions will be executed immedietely on prepared statement close. If it is set to > 1, these calls will be batched together to avoid overhead of calling sp_unprepare too often. The default for this option can be changed by calling getDefaultServerPreparedStatementDiscardThreshold().- Specified by:
getServerPreparedStatementDiscardThresholdin interfaceISQLServerConnection- Returns:
- Returns the current setting per the description.
-
setServerPreparedStatementDiscardThreshold
public void setServerPreparedStatementDiscardThreshold(int value)Description copied from interface:ISQLServerConnectionSets the behavior for a specific connection instance. This setting controls how many outstanding prepared statement discard actions (sp_unprepare) can be outstanding per connection before a call to clean-up the outstanding handles on the server is executed. If the setting is <= 1 unprepare actions will be executed immedietely on prepared statement close. If it is set to > 1 these calls will be batched together to avoid overhead of calling sp_unprepare too often.- Specified by:
setServerPreparedStatementDiscardThresholdin interfaceISQLServerConnection- Parameters:
value- Changes the setting per the description.
-
getDisableStatementPooling
public boolean getDisableStatementPooling()Description copied from interface:ISQLServerConnectionReturns the value whether statement pooling is disabled.- Specified by:
getDisableStatementPoolingin interfaceISQLServerConnection- Returns:
- true if statement pooling is disabled, false if it is enabled.
-
setDisableStatementPooling
public void setDisableStatementPooling(boolean value)Description copied from interface:ISQLServerConnectionSets the value to Disable/enable statement pooling.- Specified by:
setDisableStatementPoolingin interfaceISQLServerConnection- Parameters:
value- true to disable statement pooling, false to enable it.
-
getStatementPoolingCacheSize
public int getStatementPoolingCacheSize()Description copied from interface:ISQLServerConnectionReturns the size of the prepared statement cache for this connection. A value less than 1 means no cache.- Specified by:
getStatementPoolingCacheSizein interfaceISQLServerConnection- Returns:
- Returns the current setting per the description.
-
getStatementHandleCacheEntryCount
public int getStatementHandleCacheEntryCount()Description copied from interface:ISQLServerConnectionReturns the current number of pooled prepared statement handles.- Specified by:
getStatementHandleCacheEntryCountin interfaceISQLServerConnection- Returns:
- Returns the current setting per the description.
-
isStatementPoolingEnabled
public boolean isStatementPoolingEnabled()Description copied from interface:ISQLServerConnectionReturns whether statement pooling is enabled or not for this connection.- Specified by:
isStatementPoolingEnabledin interfaceISQLServerConnection- Returns:
- Returns the current setting per the description.
-
setStatementPoolingCacheSize
public void setStatementPoolingCacheSize(int value)Description copied from interface:ISQLServerConnectionSets the size of the prepared statement cache for this connection. A value less than 1 means no cache.- Specified by:
setStatementPoolingCacheSizein interfaceISQLServerConnection- Parameters:
value- The new cache size.
-