Written by

Question Tom Scaletti · May 25

Python - Unable to connect to 2 different databases like hive and iris in same python program

I am trying to connect to hive database and IRIS Intersystems Databases using jaydebeapi in python. I am able to connect to one database at a time. While trying to connect to other database, I am getting the below error

"Class org.apache.hive.jdbc.HiveDriver is not found"

or 

"Class com.intersystems.jdbc.IRISDriver is not found"

lin1 -

hive_con = jd.connect(java_driver_class, jdbc_conn_url, [hive_user, hive_pass],jarfile)

lin2 -

iris_con = jd.connect(iris_driver_class, iris_conn_url, [iris_user, iris_pass],jarfile)

If I try to execute the above code, only the first lin1 executes and the other one gives out exception.

If I comment out the first line, then second line lin2 works fine. I tried to close one connection before opening the other, still the issue is same. I want the the both connections to work in same program.

Comments

DC AI Bot · May 25 Bot

You can make both connections work in the same Python process, but when using jaydebeapi for two different JDBC drivers, you need to pass the paths to both JDBC jar files together in the connection call. If you pass only one jar for the first connection and then a different one for the second, the second driver class may not be found. [1]

A working pattern is to build a combined jar list like this: [1]

import jaydebeapi as jd

IRIS_JARFILE = "/path/to/intersystems-jdbc.jar"
HIVE_JARFILE = "/path/to/hive-jdbc.jar"

IRIS_DRIVER = "com.intersystems.jdbc.IRISDriver"
HIVE_DRIVER = "org.apache.hive.jdbc.HiveDriver"

JDBC_JARFILES = [IRIS_JARFILE, HIVE_JARFILE]

hive_con = jd.connect(
    HIVE_DRIVER,
    jdbc_conn_url,
    [hive_user, hive_pass],
    JDBC_JARFILES
)

iris_con = jd.connect(
    IRIS_DRIVER,
    iris_conn_url,
    [iris_user, iris_pass],
    JDBC_JARFILES
)

The key point is this:

“note connecting to two data sources in the same program requires that you

reference the paths to BOTH jar files in a list in every call. Otherwise the

second connection attempt will fail. It appears that the paths only get

added once within a process.” [1]

Your current code uses a single jarfile argument per call, which matches the single-database examples for IRIS JDBC connections, but for your two-driver case you should replace that with a list containing both jars. [1][2]

For IRIS specifically, the driver class name shown in the example is: [1][2]

com.intersystems.jdbc.IRISDriver

And the standard JayDeBeApi connection form for IRIS is: [2]

conn = jaydebeapi.connect(driver, url, [user, password], jarfile)

So the fix is not the driver name itself, but changing the last argument from one jar path to the combined list of both driver jars for both connections. [1][2]


Sources:

Tell us more:
Don't like the style
Not factually correct
Didn't fully follow instructions
Refused when it shouldn't have
Being lazy
More...
Submit
0 0
Dmitry Maslennikov · May 25

What the reason of using JDBC connection from Python?

InterSystems has DB-API driver in Python for a few years already, why would not you use it?

Hive should have db-api driver too

0