Module com.microsoft.sqlserver.jdbc
Package com.microsoft.sqlserver.jdbc

# Class SQLServerBulkCopyOptions

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

All Implemented Interfaces:
  `Serializable`

public class SQLServerBulkCopyOptions extends Object implements Serializable
Provides a collection of settings that control how an instance of SQLServerBulkCopy behaves. Used when constructing a SQLServerBulkCopy instance to change how the writeToServer methods for that instance behave.

See Also:
  - Serialized Form

## Constructor Summary

Constructors
Constructor
Description
`SQLServerBulkCopyOptions()`
Constructs a SQLServerBulkCopySettings class using defaults for all of the settings.

## Method Summary

Modifier and Type
Method
Description
`int`
`getBatchSize()`
Returns the number of rows in each batch.
`int`
`getBulkCopyTimeout()`
Returns the number of seconds for the operation to complete before it times out.
`boolean`
`isAllowEncryptedValueModifications()`
Returns if allowEncryptedValueModifications option is enabled or not
`boolean`
`isCheckConstraints()`
Returns whether constraints are to be checked while data is being inserted or not.
`boolean`
`isFireTriggers()`
Returns if the server should fire insert triggers for rows being inserted into the database.
`boolean`
`isKeepIdentity()`
Returns whether or not to preserve any source identity values.
`boolean`
`isKeepNulls()`
Returns whether to preserve null values in the destination table regardless of the settings for default values, or if they should be replaced by default values (where applicable).
`boolean`
`isTableLock()`
Returns whether SQLServerBulkCopy should obtain a bulk update lock for the duration of the bulk copy operation.
`boolean`
`isUseInternalTransaction()`
Returns whether each batch of the bulk-copy operation will occur within a transaction or not.
`void`
`setAllowEncryptedValueModifications(boolean allowEncryptedValueModifications)`
Sets whether the driver would send data as is or would decrypt the data and encrypt it again before sending to SQL Server
`void`
`setBatchSize(int batchSize)`
Sets the number of rows in each batch.
`void`
`setBulkCopyTimeout(int timeout)`
Sets the number of seconds for the operation to complete before it times out.
`void`
`setCheckConstraints(boolean checkConstraints)`
Sets whether constraints are to be checked while data is being inserted or not.
`void`
`setFireTriggers(boolean fireTriggers)`
Sets whether the server should be set to fire insert triggers for rows being inserted into the database.
`void`
`setKeepIdentity(boolean keepIdentity)`
Sets whether or not to preserve any source identity values.
`void`
`setKeepNulls(boolean keepNulls)`
Sets whether to preserve null values in the destination table regardless of the settings for default values, or if they should be replaced by default values (where applicable).
`void`
`setTableLock(boolean tableLock)`
Sets whether SQLServerBulkCopy should obtain a bulk update lock for the duration of the bulk copy operation.
`void`
`setUseInternalTransaction(boolean useInternalTransaction)`
Sets whether each batch of the bulk-copy operation will occur within a transaction or not.

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

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

## Constructor Details

### SQLServerBulkCopyOptions

public SQLServerBulkCopyOptions()
Constructs a SQLServerBulkCopySettings class using defaults for all of the settings.

## Method Details

### getBatchSize

public int getBatchSize()
Returns the number of rows in each batch. At the end of each batch, the rows in the batch are sent to the server.

Returns:
  Number of rows in each batch.

### setBatchSize

public void setBatchSize(int batchSize) throws SQLServerException
Sets the number of rows in each batch. At the end of each batch, the rows in the batch are sent to the server.

Parameters:
  `batchSize` - Number of rows in each batch.
Throws:
  `SQLServerException` - If the batchSize being set is invalid.

### getBulkCopyTimeout

public int getBulkCopyTimeout()
Returns the number of seconds for the operation to complete before it times out.

Returns:
  Number of seconds before operation times out.

### setBulkCopyTimeout

public void setBulkCopyTimeout(int timeout) throws SQLServerException
Sets the number of seconds for the operation to complete before it times out.

Parameters:
  `timeout` - Number of seconds before operation times out.
Throws:
  `SQLServerException` - If the timeout being set is invalid.

### isKeepIdentity

public boolean isKeepIdentity()
Returns whether or not to preserve any source identity values.

Returns:
  True if source identity values are to be preserved; false if they are to be assigned by the destination.

### setKeepIdentity

public void setKeepIdentity(boolean keepIdentity)
Sets whether or not to preserve any source identity values.

Parameters:
  `keepIdentity` - True if source identity values are to be preserved; false if they are to be assigned by the destination

### isKeepNulls

public boolean isKeepNulls()
Returns whether to preserve null values in the destination table regardless of the settings for default values, or if they should be replaced by default values (where applicable).

Returns:
  True if null values should be preserved; false if null values should be replaced by default values where applicable.

### setKeepNulls

public void setKeepNulls(boolean keepNulls)
Sets whether to preserve null values in the destination table regardless of the settings for default values, or if they should be replaced by default values (where applicable).

Parameters:
  `keepNulls` - True if null values should be preserved; false if null values should be replaced by default values where applicable.

### isTableLock

public boolean isTableLock()
Returns whether SQLServerBulkCopy should obtain a bulk update lock for the duration of the bulk copy operation.

Returns:
  True to obtain row locks; false otherwise.

### setTableLock

public void setTableLock(boolean tableLock)
Sets whether SQLServerBulkCopy should obtain a bulk update lock for the duration of the bulk copy operation.

Parameters:
  `tableLock` - True to obtain row locks; false otherwise.

### isUseInternalTransaction

public boolean isUseInternalTransaction()
Returns whether each batch of the bulk-copy operation will occur within a transaction or not.

Returns:
  True if the batch will occur within a transaction; false otherwise.

### setUseInternalTransaction

public void setUseInternalTransaction(boolean useInternalTransaction)
Sets whether each batch of the bulk-copy operation will occur within a transaction or not.

Parameters:
  `useInternalTransaction` - True if the batch will occur within a transaction; false otherwise.

### isCheckConstraints

public boolean isCheckConstraints()
Returns whether constraints are to be checked while data is being inserted or not.

Returns:
  True if constraints are to be checked; false otherwise.

### setCheckConstraints

public void setCheckConstraints(boolean checkConstraints)
Sets whether constraints are to be checked while data is being inserted or not.

Parameters:
  `checkConstraints` - True if constraints are to be checked; false otherwise.

### isFireTriggers

public boolean isFireTriggers()
Returns if the server should fire insert triggers for rows being inserted into the database.

Returns:
  True triggers are enabled; false otherwise.

### setFireTriggers

public void setFireTriggers(boolean fireTriggers)
Sets whether the server should be set to fire insert triggers for rows being inserted into the database.

Parameters:
  `fireTriggers` - True triggers are to be enabled; false otherwise.

### isAllowEncryptedValueModifications

public boolean isAllowEncryptedValueModifications()
Returns if allowEncryptedValueModifications option is enabled or not

Returns:
  True if allowEncryptedValueModification is set to true; false otherwise.

### setAllowEncryptedValueModifications

public void setAllowEncryptedValueModifications(boolean allowEncryptedValueModifications)
Sets whether the driver would send data as is or would decrypt the data and encrypt it again before sending to SQL Server

Use caution when specifying allowEncryptedValueModifications as this may lead to corrupting the database because the driver does not check if the data is indeed encrypted, or if it is correctly encrypted using the same encryption type, algorithm and key as the target column.

Parameters:
  `allowEncryptedValueModifications` - enables bulk copying of encrypted data between tables or databases, without decrypting the data. Typically, an application would select data from encrypted columns from one table without decrypting the data (the app would connect to the database with the column encryption setting keyword set to disabled) and then would use this option to bulk insert the data, which is still encrypted.