JDBC Tee
Supported pipeline types:
|
When you configure JDBC Tee, you specify connection information, table name, and optionally define field mappings. By default, JDBC Tee writes data to the table based on the matching field names. You can override the default field mappings by defining specific mappings.
You define generated column mappings to specify the output fields to pass the generated database column values to.
You can configure the stage to rollback an entire batch if an error occurs while writing part of the batch. You can also configure custom properties that your driver requires.
The JDBC Tee processor can use CRUD operations defined in the sdc.operation.type record header attribute to write data. You can define a default operation for records without the header attribute or value. You can also configure whether to use multi-row operations for inserts and deletes, and how to handle records with unsupported operations.
When processing data from a CDC-enabled origin, you can specify the origin change log to aid record processing. For information about Data Collector change data processing and a list of CDC-enabled origins, see Processing Changed Data.
To use a JDBC version older than 4.0, you can specify the driver class name and define a health check query.
Example
Let's assume that you are processing customer orders. You have a customer database table with an ID column as the primary key. The customer table is configured to generate a sequential number for the ID column as each row is inserted into the table. For example, the first customer row is assigned an ID of 001, and the second is assigned an ID of 002.
When you process a new customer’s order, JDBC Tee inserts the customer data to the customer table and the database returns the generated ID for that customer. JDBC Tee passes the generated ID value to a new cust_ID field in the record. The processor passes all record fields to the next stage in the pipeline for additional processing.
The following image displays a high-level overview of how JDBC Tee processes our customer order example:
Database Vendors and Drivers
The JDBC Tee processor can write data to multiple database vendors.
Database Vendor | Versions and Drivers |
---|---|
MySQL |
|
PostgreSQL |
When connecting to a PostgreSQL database, you do not need to install a JDBC driver. Data Collector includes the JDBC driver required for PostgreSQL. |
Oracle | Oracle 11g with the Oracle 11.2.0 JDBC driver |
Microsoft SQL Server | SQL Server 2017 with the Microsoft JDBC driver 4.2 for SQL Server |
Installing the JDBC Driver
For information about installing additional drivers, see Install External Libraries.
Define the CRUD Operation
The JDBC Tee processor can insert, update, or delete data. The processor writes the records based on the CRUD operation defined in a CRUD operation header attribute or in operation-related stage properties.
- CRUD operation header attribute
- You can define the CRUD operation in a CRUD operation record header attribute. The processor looks for the CRUD operation to use in the sdc.operation.type record header attribute.
- Operation stage properties
- You define a default operation in the processor properties. The processor uses the default operation when the sdc.operation.type record header attribute is not set.
Single and Multi-row Operations
JDBC Tee performs single-row operations by default. That is, it executes a SQL statement for each record. When supported by the destination database, you can configure JDBC Tee to perform multi-row operations. Depending on the sequence of the data, multi-row operations can improve pipeline performance.
When performing multi-row operations, JDBC Tee creates a single SQL statement for sequential insert rows and for sequential delete rows. JDBC Tee does not perform multi-row update operations.
For example, say the pipeline generates three insert records, followed by two update records, and two delete records. With multi-row insert enabled, the JDBC Tee generates an Insert SQL statement for the three insert records, two Update statements - one for each of the update records, and a single Delete statement for the two delete records.
INSERT INTO <table name> (<col1>, <col2>, <col3>)
VALUES (<record1 field1>,<record1 field2>,<record1 field3>),
(<r2 f1>,<r2 f2>,<r2 f3>), (<r3 f1>,<r3 f2>,<r3 f3>),...;
DELETE FROM <table name> WHERE <primary key> IN (<key1>, <key2>, <key3>,...);
DELETE FROM <table name> WHERE (<pkey1>, <pkey2>, <pkey3>)
IN ((<key1-1>, <key1-2>, <key1-3>),(<key2-1>, <key2-2>, <key2-2>),...);
Configuring a JDBC Tee
Configure a JDBC Tee processor to write data to a database table and enrich records with data from generated database columns.