0

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

“Oracle 不支持 Raspberry Pi 使用的 ARM CPU 架构。您下载并解压缩了 Oracle Instant Client,但它实际上无法运行。没有 Oracle 客户端库,cx_oracle 将无法工作,通用 Python ODBC 也无法运行连接器。”

信息:

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

我认为问题出在类路径上,但我仍然是初学者。要键入什么命令来配置它?

先感谢您 !

4

1 回答 1

1

我很确定“/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)))')
于 2019-07-01T16:25:57.830 回答