Using Bulk Load for Batch Inserts
- Last Updated: May 15, 2020
- 2 minute read
- DataDirect Connectors
- JDBC
- IBM Db2 5.1
- MySQL 5.1
- Progress OpenEdge 5.1
- SAP Sybase 5.1
- Documentation
For the Oracle, Microsoft SQL Server, and Sybase drivers, the driver uses the native bulk
load protocol for database connections when the EnableBulkLoad property is set to
true. For example, if you set the EnableBulkLoad property to
true, the driver would use bulk load for the following batch insert
request.
PreparedStatement ps = conn.prepareStatement(
"INSERT INTO employees VALUES (?, ?, ?)");
for (n = 0; n < 100; n++) {
ps.setString(name[n]);
ps.setLong(id[n]);
ps.setInt(salary[n]);
ps.addBatch();
}
ps.executeBatch();
In some cases, even when the EnableBulkLoad property is set to true, the
driver may not be able to use bulk load because of restrictions enforced by the bulk load
protocol and will downgrade to a batch mechanism. For example, if the data being loaded has a
data type that is not supported by the bulk load protocol, the driver cannot use bulk load,
but will use the batch mechanism instead.
For the Salesforce driver, when the EnableBulkLoad property is set to true
and the number of rows to be inserted in the batch is larger than BulkLoadThreshold, the
driver uses the Salesforce Bulk API instead of the Web service API.
For all drivers that support bulk load, either through native support or emulation using the batch mechanism, you can use the BulkLoadBatchSize property to specify the number of rows the driver loads at a time when loading data. Performance can be improved by increasing the number of rows the driver loads at a time because fewer network round trips are required. Be aware that increasing the number of rows that are loaded also causes the driver to consume more memory on the client.