最近,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
我的代码之前工作正常,但是有了新的更新,它停止了。有人可以告诉我我需要对代码进行哪些更改吗?
最佳答案
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
关于python - jaydebeapi最新更新至1.0.0导致连接错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41646041/