JDBC connector
The JDBC connector reads from and writes to a relational database. It can also serve as a lookup table in a lookup join.
Dialects and drivers
For lookup joins, see Creating lookup joins.
The connector is version 4.1.0, built for Flink 2.3.0. It includes dialects for PostgreSQL, MySQL, Oracle, SQL Server, and Db2, but this release supports only PostgreSQL.
The following example creates a table for a PostgreSQL table:
CREATE TABLE customers (
id INT,
name STRING,
country STRING,
PRIMARY KEY (id) NOT ENFORCED
) WITH (
'connector' = 'jdbc',
'url' = 'jdbc:postgresql://<database-host>:5432/shop',
'table-name' = 'public.customers',
'username' = '<user>',
'password' = '<password>'
);
Mandatory properties
| Property | Description |
|---|---|
connector | jdbc |
url | The JDBC URL of the database. There is no default value. |
table-name | The name of the table in the database. There is no default value. |
Optional properties
| Property | Description |
|---|---|
username and password | The credentials of the database. Set both or neither. |
scan.fetch-size | The number of rows that the source fetches in each round trip. The default is 0, which uses the default of the driver. |
scan.auto-commit | Whether the driver commits each statement. Some drivers, such as the PostgreSQL driver, need false to stream results. |
lookup.cache | Set it to PARTIAL to cache the rows of a lookup table. |
lookup.partial-cache.max-rows | The maximum number of cached rows. |
lookup.partial-cache.expire-after-write | How long a cached row is valid. |
lookup.max-retries | The number of retries when a lookup fails. The default is 3. |
sink.buffer-flush.max-rows | The number of rows after which the sink writes its buffer. The default is 100. |
sink.buffer-flush.interval | The time after which the sink writes its buffer. The default is 1 second. |
sink.max-retries | The number of retries when a write fails. The default is 3. |
connection.max-retry-timeout | The maximum time between connection retries. The default is 60 seconds. |
For the full list of options, see JDBC SQL connector in the Apache Flink documentation.
A sink writes in upsert mode if the table has a primary key, and in append mode if it does not.
