我尝试从Raspberry pi用python发出Oracle请求。问题是:
“ Oracle不支持Raspberry Pi使用的ARM CPU架构。您下载并解压缩了Oracle Instant Client,但实际上无法运行。而且如果没有Oracle Client库,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
我认为问题是类路径,但是我仍然是初学者。键入什么命令来配置它?
先谢谢您!
答案 0 :(得分:0)
我很确定'/ 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 light client 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)))')