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

Table 1. Mandatory properties of the JDBC connector
PropertyDescription
connectorjdbc
urlThe JDBC URL of the database. There is no default value.
table-nameThe name of the table in the database. There is no default value.

Optional properties

Table 2. Optional properties of the JDBC connector
PropertyDescription
username and passwordThe credentials of the database. Set both or neither.
scan.fetch-sizeThe number of rows that the source fetches in each round trip. The default is 0, which uses the default of the driver.
scan.auto-commitWhether the driver commits each statement. Some drivers, such as the PostgreSQL driver, need false to stream results.
lookup.cacheSet it to PARTIAL to cache the rows of a lookup table.
lookup.partial-cache.max-rowsThe maximum number of cached rows.
lookup.partial-cache.expire-after-writeHow long a cached row is valid.
lookup.max-retriesThe number of retries when a lookup fails. The default is 3.
sink.buffer-flush.max-rowsThe number of rows after which the sink writes its buffer. The default is 100.
sink.buffer-flush.intervalThe time after which the sink writes its buffer. The default is 1 second.
sink.max-retriesThe number of retries when a write fails. The default is 3.
connection.max-retry-timeoutThe 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.