Python: JDBC Connection Error using JayDeBeApi

Viewed 5937

I'm facing an error while running following code. Please help me solving this issue or suggest an alternative way to connect Vertica server via JDBC.

I have also tried connecting using pyspark. But with pyspark we are not able to execute sql query in vertica server.

System Configuration:

Linux with python 3.7.0

jaydebeapi version - 1.1.1

jpype version - 0.7.2

import jaydebeapi
import jpype

jdbc_url = 'jdbc:vertica://XX.XX.XXX.XXX/DATA?XXXXX'
vertica_properties={"user": "XXXX", "password": "XXXXX"}

jars = ['XXXX/vertica-jdbc-9.3.1-0.jar', 
        'XXXX/vertica-spark2.1_scala2.11.jar', 
        'XXXX/CustomVerticaDialect.jar']

connection = jaydebeapi.connect(jclassname='com.vertica.jdbc.Driver', url=jdbc_url, driver_args=vertica_properties, jars=jars)
connection

ERROR

--------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-cc7d2752ecd8> in <module>()
----> 1 connection = jaydebeapi.connect(jclassname='com.vertica.jdbc.Driver', url=jdbc_url, driver_args=vertica_properties, jars=jars)
      2 connection

/BDAPP/python/anaconda3/lib/python3.7/site-packages/jaydebeapi/__init__.py in connect(jclassname, url, driver_args, jars, libs)
    379     else:
    380         libs = []
--> 381     jconn = _jdbc_connect(jclassname, url, driver_args, jars, libs)
    382     return Connection(jconn, _converters)
    383 

/BDAPP/python/anaconda3/lib/python3.7/site-packages/jaydebeapi/__init__.py in _jdbc_connect_jpype(jclassname, url, driver_args, jars, libs)
    180         types = jpype.java.sql.Types
    181         types_map = {}
--> 182         for i in types.__javaclass__.getClassFields():
    183             types_map[i.getName()] = i.getStaticAttribute()
    184         _init_types(types_map)

AttributeError: type object 'java.sql.Types' has no attribute '__javaclass__'
2 Answers

The jaydebeapi seems to be incompatible with jpype 0.7.2 as of Mar 2020. Here is the github page that points out this issue: http://github.com/baztian/jaydebeapi/issues/99.

The solution as per the github page is to downgrade jpype to jpype 0.6.3 using either:

pip install JPype1==0.6.3 --force-reinstall

or

conda install -c conda-forge JPype1=0.6.3 --force-reinstall

Downgrading jpype worked for me

Please upgrade to JayDeBeApi>=1.2.1. Starting from JPype1 0.7.0 some non backwards compatible changes have been introduced. Newer JayDeBeApi versions can deal with that.

pip install --upgrade JayDeBeApi
Related