jaydebeapi最新更新到1.0.0导致连接错误

时间:2017-01-14 01:59:22

标签: python jaydebeapi

最近,jaydebeapi更新了,我现在无法连接我的旧代码。 https://github.com/baztian/jaydebeapi

这是关于连接的jaydebeapi来源的文档:

>>> import jaydebeapi
>>> conn = jaydebeapi.connect('org.hsqldb.jdbcDriver',
...                           'jdbc:hsqldb:mem:.',
...                           ['SA', ''],
...                           '/path/to/hsqldb.jar',)
>>> curs = conn.cursor()

这就是我这样做的方式:

 53     curs, conn = None, None
 54     try:
 55         thisdir = os.path.dirname(os.path.abspath(__file__))
 56 
 57         join = os.path.join
 58         conn = jaydebeapi.connect('com.teradata.jdbc.TeraDriver',
 59                                   ['jdbc:teradata://%s/CHARSET=UTF8' % system, username, password],
 60                                   jars=[join(thisdir, 'lib/tdgssconfig.jar'),
 61                                         join(thisdir, 'lib/terajdbc4.jar')])
 62 
 63 
 64         curs = conn.cursor()

我得到的错误:

  join(thisdir, 'lib/terajdbc4.jar')])
      File "/app/.heroku/python/lib/python2.7/site-packages/jaydebeapi/__init__.py", line 380, in connect
        jconn = _jdbc_connect(jclassname, url, driver_args, jars, libs)
      File "/app/.heroku/python/lib/python2.7/site-packages/jaydebeapi/__init__.py", line 199, in _jdbc_connect_jpype
        return jpype.java.sql.DriverManager.getConnection(url, *dargs)
    RuntimeError: No matching overloads found. at native/common/jp_method.cpp:121

我的代码之前正在运行,但随着新的更新,它停止了。有人能告诉我我需要对我的代码做出哪些更改吗?

1 个答案:

答案 0 :(得分:2)

conn = jaydebeapi.connect('com.teradata.jdbc.TeraDriver',
                          'jdbc:teradata://%s/CHARSET=UTF8' % system,
                          [username, password],
                          jars=[join(thisdir, 'lib/tdgssconfig.jar'),
                                     join(thisdir, 'lib/terajdbc4.jar')])

应该做的伎俩。使用JayDeBeApi 1.0.0,您现在可以将连接属性指定为字典:

conn = jaydebeapi.connect('com.teradata.jdbc.TeraDriver',
                          'jdbc:teradata://%s',
                          {'user': username, 'password': password,
                           'CHARSET': 'UTF8'},
                          jars=[join(thisdir, 'lib/tdgssconfig.jar'),
                                     join(thisdir, 'lib/terajdbc4.jar')])

changelog通知潜在的不兼容性。 connect方法的参数已经改变,应该更加清晰。文档也正确更新。

看看

>>> help(jaydebeapi.connect)

connect(jclassname, url, driver_args=None, jars=None, libs=None)
    Open a connection to a database using a JDBC driver and return
    a Connection instance.

    jclassname: Full qualified Java class name of the JDBC driver.
    url: Database url as required by the JDBC driver.
    driver_args: Dictionary or sequence of arguments to be passed to
           the Java DriverManager.getConnection method. Usually
           sequence of username and password for the db. Alternatively
           a dictionary of connection arguments (where `user` and
           `password` would probably be included). See
           http://docs.oracle.com/javase/7/docs/api/java/sql/DriverManager.html
           for more details
    jars: Jar filename or sequence of filenames for the JDBC driver
    libs: Dll/so filenames or sequence of dlls/sos used as shared
          library by the JDBC driver