The Microsoft JDBC driver can translate a compatible prepared batch insert into its bulk-copy path. Add useBulkCopyForBatchInsert=true to the connection, keep the SQL shape simple, and execute batches inside an explicit transaction.
Last updated: October 10, 2026.
String url = "jdbc:sqlserver://db01:1433;"
+ "databaseName=Sales;encrypt=true;"
+ "useBulkCopyForBatchInsert=true";
try (Connection connection = DriverManager.getConnection(url, user, password);
PreparedStatement statement = connection.prepareStatement(
"INSERT INTO dbo.Events (event_id, payload) VALUES (?, ?)")) {
connection.setAutoCommit(false);
for (Event event : events) {
statement.setLong(1, event.id());
statement.setString(2, event.payload());
statement.addBatch();
}
statement.executeBatch();
connection.commit();
}Keep credentials outside source code and use the driver version approved for your application. Start with a moderate batch size, record elapsed time and transaction-log growth, and compare the result with the ordinary batch path on production-like data.
Confirm that the insert is eligible
Microsoft documents bulk copy for batch insert for PreparedStatement.executeBatch() and CallableStatement.executeBatch(). The query must begin with an INSERT and use a supported form. Complex expressions, unsupported types, or SQL that depends on per-row generated results may require the regular execution path.
Do not assume that one enormous batch is fastest. Large batches increase memory use, lock duration, and rollback cost. Commit logical chunks and retain a stable application key so a failed chunk can be investigated without duplicating rows.
Configure and measure the connection deliberately
The driver lists useBulkCopyForBatchInsert among its official connection properties. Set it in the JDBC URL or data source configuration, then verify the effective configuration used by the connection pool. Test triggers, constraints, identity behavior, and error reporting before rollout.
Bulk copy improves the transport path; it does not replace suitable indexes or transaction design. Continue with JDBC timeout configuration, safe SQL Server procedure deployment, and SQL Server backup verification.