Python:使用JayDeBeApi的JDBC连接错误

时间:2020-03-18 15:28:50

标签: java python jdbc jpype jaydebeapi

运行以下代码时遇到错误。请帮助我解决此问题,或建议通过JDBC连接Vertica服务器的另一种方法。

我也尝试过使用pyspark连接。但是,使用pyspark无法在vertica服务器中执行sql查询。

系统配置:

具有python 3.7.0的Linux

jaydebeapi版本-1.1.1

jpype版本-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

错误

--------------------------------------------------------------------------
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 个答案:

答案 0 :(得分:2)

截至2020年3月,jaydebeapi似乎与jpype 0.7.2不兼容。这是指出此问题的github页面:http://github.com/baztian/jaydebeapi/issues/99

根据github页面的解决方案是使用以下任一方法将jpype降级为jpype 0.6.3:

pip install JPype1==0.6.3 --force-reinstall

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

降级jpype对我有用

答案 1 :(得分:1)

请升级到JayDeBeApi> = 1.2.1。从JPype1 0.7.0开始,引入了一些非向后兼容的更改。较新的JayDeBeApi版本可以解决这个问题。

self.Employee1_FirstDay_ActualShift.set(  items[0][0])
self.Employee1_SecondDay_ActualShift.set( items[1][0])
self.Employee1_ThirdDay_ActualShift.set(  items[2][0])
self.Employee1_FourthDay_ActualShift.set( items[3][0])
self.Employee1_FifthDay_ActualShift.set(  items[4][0])
self.Employee1_SixthDay_ActualShift.set(  items[5][0])
self.Employee1_SeventhDay_ActualShift.set(items[6][0])