SQLServerBulkCopy Class
- java.
lang. Object - com.
microsoft. sqlserver. jdbc. SQLServerBulkCopy
- com.
Implements
public class SQLServerBulkCopy
implements java.lang.AutoCloseable, java.io.Serializable
Provides functionality to efficiently bulk load a SQL Server table with data from another source.
Microsoft SQL Server includes a popular command-prompt utility named bcp for moving data from one table to another, whether on a single server or between servers. The SQLServerBulkCopy class lets you write code solutions in Java that provide similar functionality. There are other ways to load data into a SQL Server table (INSERT statements, for example), but SQLServerBulkCopy offers a significant performance advantage over them. The SQLServerBulkCopy class can be used to write data only to SQL Server tables. However, the data source is not limited to SQL Server; any data source can be used, as long as the data can be read with a ResultSet or ISQLServerBulkRecord instance.
Constructor Summary
Constructor | Description |
---|---|
SQLServerBulkCopy(String connectionUrl) |
Constructs a SQLServer |
SQLServerBulkCopy(Connection connection) |
Constructs a SQLServer |
Method Summary
Modifier and Type | Method and Description |
---|---|
void |
addColumnMapping(int sourceColumn, int destinationColumn)
Adds a new column mapping, using ordinals to specify both the source and destination columns. |
void |
addColumnMapping(int sourceColumn, String destinationColumn)
Adds a new column mapping, using an ordinal for the source column and a string for the destination column. |
void |
addColumnMapping(String sourceColumn, int destinationColumn)
Adds a new column mapping, using a column name to describe the source column and an ordinal to specify the destination column. |
void |
addColumnMapping(String sourceColumn, String destinationColumn)
Adds a new column mapping, using column names to specify both source and destination columns. |
void |
clearColumnMappings()
Clears the contents of the column mappings |
void |
close()
Closes the SQLServer |
SQLServer |
getBulkCopyOptions()
Returns the current SQLServer |
java.lang.String |
getDestinationTableName()
Returns the name of the destination table on the server. |
protected java.lang.Object |
getTemporalObjectFromCSVWithFormatter(String valueStrUntrimmed, int srcJdbcType, int srcColOrdinal, DateTimeFormatter dateTimeFormatter)
Returns the temporal object from CSV This method is called against jdbc41, but it require jdbc42 to work therefore, we will throw exception. |
void |
setBulkCopyOptions(SQLServerBulkCopyOptions copyOptions)
Update the behavior of the SQLServer |
void |
setDestinationTableName(String tableName)
Sets the name of the destination table on the server. |
void |
writeToServer(ISQLServerBulkData sourceData)
Copies all rows from the supplied ISQLServer |
void |
writeToServer(ResultSet sourceData)
Copies all rows in the supplied Result |
void |
writeToServer(RowSet sourceData)
Copies all rows in the supplied Row |
Methods inherited from java.lang.Object
Constructor Details
SQLServerBulkCopy
public SQLServerBulkCopy(String connectionUrl)
Constructs a SQLServerBulkCopy based on the supplied connectionString.
Parameters:
Throws:
SQLServerBulkCopy
public SQLServerBulkCopy(Connection connection)
Constructs a SQLServerBulkCopy using the specified open instance of SQLServerConnection.
Parameters:
Throws:
Method Details
addColumnMapping
public void addColumnMapping(int sourceColumn, int destinationColumn)
Adds a new column mapping, using ordinals to specify both the source and destination columns.
Parameters:
Throws:
addColumnMapping
public void addColumnMapping(int sourceColumn, String destinationColumn)
Adds a new column mapping, using an ordinal for the source column and a string for the destination column.
Parameters:
Throws:
addColumnMapping
public void addColumnMapping(String sourceColumn, int destinationColumn)
Adds a new column mapping, using a column name to describe the source column and an ordinal to specify the destination column.
Parameters:
Throws:
addColumnMapping
public void addColumnMapping(String sourceColumn, String destinationColumn)
Adds a new column mapping, using column names to specify both source and destination columns.
Parameters:
Throws:
clearColumnMappings
public void clearColumnMappings()
Clears the contents of the column mappings
close
public void close()
Closes the SQLServerBulkCopy instance
getBulkCopyOptions
public SQLServerBulkCopyOptions getBulkCopyOptions()
Returns the current SQLServerBulkCopyOptions.
Returns:
getDestinationTableName
public String getDestinationTableName()
Returns the name of the destination table on the server.
Returns:
getTemporalObjectFromCSVWithFormatter
protected Object getTemporalObjectFromCSVWithFormatter(String valueStrUntrimmed, int srcJdbcType, int srcColOrdinal, DateTimeFormatter dateTimeFormatter)
Returns the temporal object from CSV This method is called against jdbc41, but it require jdbc42 to work therefore, we will throw exception.
Parameters:
Returns:
Throws:
setBulkCopyOptions
public void setBulkCopyOptions(SQLServerBulkCopyOptions copyOptions)
Update the behavior of the SQLServerBulkCopy instance according to the options supplied, if supplied SQLServerBulkCopyOption is not null.
Parameters:
Throws:
setDestinationTableName
public void setDestinationTableName(String tableName)
Sets the name of the destination table on the server.
Parameters:
Throws:
writeToServer
public void writeToServer(ISQLServerBulkData sourceData)
Copies all rows from the supplied ISQLServerBulkRecord to a destination table specified by the destinationTableName property of the SQLServerBulkCopy object.
Parameters:
Throws:
writeToServer
public void writeToServer(ResultSet sourceData)
Copies all rows in the supplied ResultSet to a destination table specified by the destinationTableName property of the SQLServerBulkCopy object.
Parameters:
Throws:
writeToServer
public void writeToServer(RowSet sourceData)
Copies all rows in the supplied RowSet to a destination table specified by the destinationTableName property of the SQLServerBulkCopy object.
Parameters:
Throws: