When you send Dataflow output to relational databases, you often need to maintain custom connector code and manually apply updates for security and bug fixes. To reduce this maintenance work, you can use Dataflow managed I/O to configure connections with a single key-value configuration and receive automatic upgrades. You can configure your project dependencies to write records to Java Database Connectivity (JDBC) databases, such as PostgreSQL, MySQL, and Microsoft SQL Server. For SDK requirements and JDBC configuration parameters, see Dataflow managed I/O for databases.
Dependencies
Add the following dependencies to your project:
Java
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-managed</artifactId>
<version>${beam.version}</version>
</dependency>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-io-jdbc</artifactId>
<version>${beam.version}</version>
</dependency>
Example
The following example writes a few example records to a PostgreSQL database. While this example uses PostgreSQL, configuring other supported databases is similar.
Java
To authenticate to Dataflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
What's next
- Read from Databases.
- Learn more about Managed I/O.