import com.microsoft.sqlserver.jdbc.*;
long startTime = System.currentTimeMillis();
SQLServerBulkCSVFileRecord fileRecord = null;
fileRecord = new SQLServerBulkCSVFileRecord("C:\\temp\\test.txt", true);
fileRecord.addColumnMetadata(1, null, java.sql.Types.NVARCHAR, 50, 0);
fileRecord.addColumnMetadata(2, null, java.sql.Types.INTEGER, 0, 0);
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection destinationConnection = DriverManager.getConnection("jdbc:sqlserver://Server\\\\Instance:1433", "user", "pass");
SQLServerBulkCopyOptions copyOptions = new SQLServerBulkCopyOptions();
copyOptions.setBatchSize(300000);
copyOptions.setTableLock(true);
SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(destinationConnection);
bulkCopy.setBulkCopyOptions(copyOptions);
bulkCopy.setDestinationTableName("TestTable");
bulkCopy.writeToServer(fileRecord);
long endTime = System.currentTimeMillis();
long totalTime = endTime - startTime;
System.out.println(totalTime + "ms");