JDBC Driver for Salesforce Marketing Cloud

Build 22.0.8462

Batch Processing

The CData JDBC Driver for Salesforce Marketing Cloud enables you to take advantage of the bulk load support in Salesforce Marketing Cloud through the JDBC batch API. You can use the batch API to execute related SQL data manipulation statements simultaneously.

Using the JDBC Batch API

The following examples show how to execute bulk operations with the PreparedStatement class.

Bulk Insert

To perform a bulk insert with a PreparedStatement, call addBatch for each set of parameters you want to execute as part of the bulk insert. After adding all the sets of parameters to the batch, you can execute the bulk insert by calling executeBatch.

The executeBatch method returns an array that contains the update counts for each statement. For example:

To retrieve the primary keys for new records, set the Statement.RETURN_GENERATED_KEYS flag when you call prepareStatement and then call the getGeneratedKeys method after you call executeBatch.

String query = "INSERT INTO Subscriber (Status) VALUES(?)"; 
PreparedStatement pstmt = conn.prepareStatement(query,Statement.RETURN_GENERATED_KEYS);

pstmt.setString(1, "Jon Doe"); 
pstmt.addBatch();

pstmt.setString(1, "John"); 
pstmt.addBatch();

int[] r = pstmt.executeBatch();
for(int i: r)
  System.out.println(i);

ResultSet rs = pstmt.getGeneratedKeys();
while(rs.next()){    
  System.out.println(rs.getString("Id"));
}

Setting the Batch Size

Setting the maximum batch size can be necessary when the server has limitations on the size of the request that can be submitted. Set the BatchSize property to split the entire batch into batches of the specified value. Each batch is submitted to the server individually.

Or, set BatchSize to 0 to submit the entire batch.

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8462