来自覆盆子的 jaydebeapi 的问题类路径

Problem Classpath for jaydebeapi from raspberry

我尝试在 python 中从 Raspberry pi 发出 Oracle 请求。问题是:

"Oracle does not support the ARM CPU architecture which the Raspberry Pi uses. You downloaded and unzipped the Oracle Instant Client, but it can't actually run. And without the Oracle Client libraries, cx_oracle will not work, and neither will generic Python ODBC connectors."

信息:

Apache Maven 3.2.5 
Maven home: /opt/apache-maven-3.2.5
Java version: 1.8.0_212, vendor: Raspbian
Java home: /usr/lib/jvm/java-8-openjdk-armhf/jre
Default locale: fr_FR, platform encoding: UTF-8
OS name: "linux", version: "4.19.42-v7+", arch: "arm", family: "unix"

ojdbc6.jar的位置是:

/home/pi/ojdbc6.jar

我需要 python,所以安装了 JPype 和 JayDeBeApi,我在 jupyter notebopok 上写了这个:

import jaydebeapi
import jpype
import os
conn= jaydebeapi.connect('oracle.jdbc.driver.OracleDriver',
'[admin]/[root]@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=helloworld.com)(PORT=1521))(CONNECT_DATA=(SID=hello42)))',
'/home/pi/ojdbc6.jar')

但是我有这个错误:

---------------------------------------------------------------------------
java.lang.RuntimeExceptionPyRaisable      Traceback (most recent call last)
<ipython-input-12-2085c24bdf88> in <module>
----> 1 conn=jaydebeapi.connect('oracle.jdbc.driver.OracleDriver','[admin]/[root]@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=helloworld.com)(PORT=1521))(CONNECT_DATA=(SID=hello42)))','/home/pi/ojdbc6.jar')

/usr/local/lib/python3.5/dist-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 

/usr/local/lib/python3.5/dist-packages/jaydebeapi/__init__.py in _jdbc_connect_jpype(jclassname, url, driver_args, jars, libs)
    188             return jpype.JArray(jpype.JByte, 1)(data)
    189     # register driver for DriverManager
--> 190     jpype.JClass(jclassname)
    191     if isinstance(driver_args, dict):
    192         Properties = jpype.java.util.Properties

/usr/local/lib/python3.5/dist-packages/jpype/_jclass.py in JClass(name)
     71     jc = _jpype.findClass(name)
     72     if jc is None:
---> 73         raise _RUNTIMEEXCEPTION.PYEXC("Class %s not found" % name)
     74 
     75     return _getClassFor(jc)

java.lang.RuntimeExceptionPyRaisable: java.lang.RuntimeException: Class oracle.jdbc.driver.OracleDriver not found

我认为是类路径的问题,但我还是个初学者。键入什么命令来配置它?

提前致谢!

我很确定 '/home/pi/ojdbc6.jar' 当前被视为 driver_args而不是 jars 变量。

正确的做法:

conn=jaydebeapi.connect('oracle.jdbc.driver.OracleDriver',
'[admin]/[root]@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=helloworld.com)(PORT=1521))(CONNECT_DATA=(SID=hello42)))',
jars='/home/pi/ojdbc6.jar')

或者您可以手动将 Oracle 轻客户端 jar 添加到 jpype 类路径。

jpype.startJVM(jpype.getDefaultJVMPath(), '-Djava.class.path=/home/pi/ojdbc6.jar'
conn=jaydebeapi.connect('oracle.jdbc.driver.OracleDriver',
'[admin]/[root]@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=helloworld.com)(PORT=1521))(CONNECT_DATA=(SID=hello42)))')