Puja Shaw
Puja Shaw

Reputation: 145

How to create connection for DB2 database in Apache Airflow(2.2.5)

I need to poll DB2 database table until a record is created and once it is successful,i need to trigger a task in dag. For this I have to do below:

  1. Create a DB2 connection in airflow
  2. Use SQL sensor to poll db table using the connection created in above step.

But I don't see the connection type option for DB2 (screenshot attached). Do I have to install something? Please help.

PS: I am new to Airflow.

enter image description here

Upvotes: 0

Views: 2225

Answers (3)

Allen
Allen

Reputation: 3

I have tried to connect to DB2 successfully on Airflow 2.2.5.

Airflow doesn't has specific provider for DB2. You need to use JDBC to connect. So you need to install some libraries of Airflow and download DB2 JDBC driver to fulfill this task. List of all libs and provider need to install below:

  1. Apache-airflow-provider-jdbc/Version:2.1.3
  2. JayDeBeApi/Version:latest
  3. JPype1/Version:latest

You also need to download DB2 JDBC drivers. This driver include some packages and license file like:

  1. db2jcc4.jar
  2. sqlj4.zip
  3. jdbc4_LI_en

Because it will use JDBC to connect,openJDK also need to install on your docker. Setting environment variables JAVA_HOME, PATH and CLASSPATH are needed.

All of above actions can be done on your docker file.

When you have completed to build your image, You can start your airflow to set connection.

  • Connection URL syntax: jdbc:db2://Host:Port/Database You can replace HOST,PORT and Database.

  • Driver Path: You can input where your class file(db2jcc4.jar) located.

Hope these tips can help you. I am New to Airflow too.

Upvotes: 0

juan carlos gonzalez
juan carlos gonzalez

Reputation: 26

Yes the airflow connection does not appear to be a specific connection for db2, so you have to choose generic in connection Type. I also recommend to install the security mechanism for connection. the next package: pip install airflow-provider-db2

Upvotes: 0

Elad Kalif
Elad Kalif

Reputation: 15921

There is no DB2 specific connection.

For general connections you can just use the Generic connection: enter image description here

For older Airflow versions that doesn't have Generic connection you can use any other connection type (HTTP/MySql for example). It doesn't really matter. Airflow looks for connection by the connection id. The type is almost meaningless in that perspective.

Upvotes: 1

Related Questions