1

在尝试通过 JDBC 连接到数据库时,我构建了 JPype (JPype1-0.5.5.4) 和 JayDeBeAPI 0.1.4。这是在 RHEL 上。我可以使用驱动程序成功连接,

TrgtCnn = jaydebeapi.connect('com.ibm.as400.access.AS400JDBCDriver',
                          ['jdbc:as400://<mask>','<mask>','<mask>'],
                          '/app/as/lib/jdbc/jt400.jar')

但是当我执行 SQL 时,我在 JPype 中得到了这个回溯:

TrgtCrs = TrgtCnn.cursor()
TrgtCrs.execute("SELECT * FROM WA6U999S")

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-5d46ea8c382d> in <module>()
----> 1 TrgtCrs.execute("SELECT * FROM WA6U999S")

/app/as/opt/anaconda/lib/python2.7/site-packages/jaydebeapi/dbapi2.pyc in execute(self, operation, parameters)
    356             parameters = ()
    357         self._close_last()
--> 358         self._prep = self._connection.jconn.prepareStatement(operation)
    359         self._set_stmt_parms(self._prep, parameters)
    360         is_rs = self._prep.execute()

/app/as/opt/anaconda/lib/python2.7/site-packages/JPype1-0.5.5.4-py2.7-linux-x86_64.egg/jpype/_jclass.pyc in _getClassFor(javaClass)
     66         return _CLASSES[name]
     67 
---> 68     pyJavaClass = _JavaClass(javaClass)
     69     _CLASSES[name] = pyJavaClass
     70     return pyJavaClass

/app/as/opt/anaconda/lib/python2.7/site-packages/JPype1-0.5.5.4-py2.7-linux-x86_64.egg/jpype/_jclass.pyc in __new__(mcs, jc)
    123         elif not jc.isInterface():
    124             bjc = jc.getBaseClass(jc)
--> 125             bases.append(_getClassFor(bjc))
    126 
    127         if _JAVATHROWABLE is not None and jc.isSubclass("java.lang.Throwable"):

/app/as/opt/anaconda/lib/python2.7/site-packages/JPype1-0.5.5.4-py2.7-linux-x86_64.egg/jpype/_jclass.pyc in _getClassFor(javaClass)
     66         return _CLASSES[name]
     67 
---> 68     pyJavaClass = _JavaClass(javaClass)
     69     _CLASSES[name] = pyJavaClass
     70     return pyJavaClass

/app/as/opt/anaconda/lib/python2.7/site-packages/JPype1-0.5.5.4-py2.7-linux-x86_64.egg/jpype/_jclass.pyc in __new__(mcs, jc)
    166         for i in _CUSTOMIZERS:
    167             if i.canCustomize(name, jc):
--> 168                 i.customize(name, jc, bases, members)
    169 
    170         # remove multiple bases that would cause a MRO problem

/app/as/opt/anaconda/lib/python2.7/site-packages/JPype1-0.5.5.4-py2.7-linux-x86_64.egg/jpype/_properties.pyc in customize(self, class_name, jc, bases, members)
     68 
     69         def customize(self, class_name, jc, bases, members) :
---> 70                 accessor_pairs = _extract_accessor_pairs(members)
     71                 for attr_name, (getter, setter) in accessor_pairs.items():
     72                         if attr_name in members:

/app/as/opt/anaconda/lib/python2.7/site-packages/JPype1-0.5.5.4-py2.7-linux-x86_64.egg/jpype/_properties.pyc in _extract_accessor_pairs(members)
     46                         if _is_java_method(members[property_name]):
     47                                 continue
---> 48                 if access == 'get' and member.isBeanAccessor():
     49                         try:
     50                                 pair = accessor_pairs[property_name]

AttributeError: 'property' object has no attribute 'isBeanAccessor'

我不知道从哪里开始,而且似乎找不到任何提到这个问题的东西。

4

1 回答 1

3

这似乎是JPype 中的一个错误

我无权访问 AS/400 数据库,但我确实有一个 Oracle XE 数据库,我能够使用它来重现问题。我使用的 Python 代码如下:

#!/usr/bin/python
import jaydebeapi
conn = jaydebeapi.connect('oracle.jdbc.OracleDriver', ['jdbc:oracle:thin:@localhost:1521:XE', 'user', 'password'])
print conn

我发现了我认为可以解决问题的方法,我已将其发布到上面的 JPype 问题中。此修复是在 中编辑函数_extract_accessor_pairsjpype/_properties.py找到以下代码并将 替换orand

    for name, member in members.items():
            if not (len(name) > _PROPERTY_ACCESSOR_PREFIX_LEN \
                          or _is_java_method(member)):
                    continue
            # rest of loop omitted...

进行此更改后,我遇到的错误消失了。欢迎您尝试此修复程序,看看它是否也适合您。

于 2014-08-30T15:03:45.260 回答