Class JdbcSink


  • @PublicEvolving
    public class JdbcSink
    extends Object
    Facade to create JDBC sinks.
    • Method Detail

      • sink

        public static <T> org.apache.flink.streaming.api.functions.sink.SinkFunction<T> sink​(String sql,
                                                                                             JdbcStatementBuilder<T> statementBuilder,
                                                                                             JdbcExecutionOptions executionOptions,
                                                                                             JdbcConnectionOptions connectionOptions)
        Create a JDBC sink.

        Note: the objects passed to the return sink can be processed in batch and retried. Therefore, objects can not be reused.

        Type Parameters:
        T - type of data in StreamRecord.
        Parameters:
        sql - arbitrary DML query (e.g. insert, update, upsert)
        statementBuilder - sets parameters on PreparedStatement according to the query
        executionOptions - parameters of execution, such as batch size and maximum retries
        connectionOptions - parameters of connection, such as JDBC URL
      • exactlyOnceSink

        public static <T> org.apache.flink.streaming.api.functions.sink.SinkFunction<T> exactlyOnceSink​(String sql,
                                                                                                        JdbcStatementBuilder<T> statementBuilder,
                                                                                                        JdbcExecutionOptions executionOptions,
                                                                                                        JdbcExactlyOnceOptions exactlyOnceOptions,
                                                                                                        org.apache.flink.util.function.SerializableSupplier<XADataSource> dataSourceSupplier)
        Create JDBC sink which provides exactly-once guarantee.

        Note: the objects passed to the return sink can be processed in batch and retried. Therefore, objects can not be reused.

        Type Parameters:
        T - type of data in StreamRecord.
        Parameters:
        sql - arbitrary DML query (e.g. insert, update, upsert)
        statementBuilder - sets parameters on PreparedStatement according to the query
        executionOptions - parameters of execution, such as batch size and maximum retries
        exactlyOnceOptions - exactly-once options. Note: maxRetries setting must be strictly set to 0 for the created sink to work properly and not to produce duplicates. See issue FLINK-22311 for details.
        dataSourceSupplier - supplies the XADataSource