Unable to setup a DB2 / DashDB JDBC Connection in

2019-07-09 11:24发布

问题:

I'm trying to create a DB2 / DashDB connection using the Airflow UI. I have added the db2jcc4.jar driver and provided the path as well as the class name com.ibm.db2.jcc.DB2Driver.class

I tried to run a simple query (in the ad hoc UI) and always get the same error

java.lang.RuntimeException: Class com.ibm.db2.jcc.DB2Driver.class not found

Did anybody need to setup a DB2 / DashDB connection in Apache Airflow before?

Found nothing on the web about that.

Thanks

回答1:

May be stupid thing to check but make sure you dont have any leading blank space in connection url, driver path and driver class. Also "airflow" user (or whoever is running airflow process should have access to the driver path.



回答2:

If you haven't still figured this out, I ran into same problem.

With some debugging I came to find that the file jdbc_hook.py here https://github.com/apache/incubator-airflow/blob/master/airflow/hooks/jdbc_hook.py#L55 is missing 1 parameter expected in the jaydebeapi.connect method call.

In particular is missing the second parameter, which should be the URL of the connection.

I changed the code inside the method get_conn to the following to try out, and it worked.

  def get_conn(self):
    ......

    conn = jaydebeapi.connect(jdbc_driver_name,
                             host,
                      driver_args=[str(login), str(psw)],
                              jars=jdbc_driver_loc)
    return conn    

Notice the host added to the call to jaydebeapi.connect.

I was thinking of opening a PR, but then reviewing, they have already something in a couple of places (search for jdbc in Airflow's PRs):

https://github.com/apache/incubator-airflow/pull/2227