0

I try to make Oracle request in python from Raspberry pi. The problem is:

"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."

Info:

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"

The location of ojdbc6.jar is:

/home/pi/ojdbc6.jar

I need python, so installed JPype and JayDeBeApi and I wrote this on 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')

But i have this error:

---------------------------------------------------------------------------
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

I think the problem is the classpath, but I am still a beginner. What would be the commands to type to configure this?

thank you in advance !

Jeremy.l71
  • 45
  • 7
  • Where did the initial message which starts with `Oracle does not support the ARM CPU architecture which the Raspberry Pi uses` that you included in your question come from? This would appear to mean that you can't connect to an Oracle database from a machine based on the ARM CPU (such as a Raspberry Pi). ??? – Bob Jarvis - Слава Україні Jul 01 '19 at 16:24
  • In this post : https://stackoverflow.com/questions/55221401/tell-me-how-to-access-oracledb-from-raspberry-pi-through-query :) – Jeremy.l71 Jul 01 '19 at 18:17

1 Answers1

1

I'm pretty sure that the '/home/pi/ojdbc6.jar' is currently treated as driver_args instead of jars variable.

The correct way:

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')

Alternatively you can add the Oracle light client jar manually to jpype classpath.

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)))')
käyrätorvi
  • 371
  • 1
  • 9
  • I tried this, but i had this message : "oserror jvm is already started" :o I will try again tomorrow, thanks for you help ! – Jeremy.l71 Jul 01 '19 at 18:20
  • Got it. Indeed if the JVM has already been started, the classes aren't loaded to the classpath. Find the place where the JVM is started (it can be an explicit call to **jpype** or something else e.g. **jaydebeapi.connect(..)** ) and make the necessary clanges to the classpath. – käyrätorvi Jul 01 '19 at 20:51
  • If you're up for it, check out the source code at https://github.com/baztian/jaydebeapi/blob/master/jaydebeapi/__init__.py#L158 which actually explains everything that is happening. – käyrätorvi Jul 01 '19 at 20:52
  • Your code in "The correct way" give me this: ```python java.sql.SQLExceptionPyRaisable: java.sql.SQLException: No suitable driver found for [admin]/[root]@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=helloworld.com)(PORT=1521))(CONNECT_DATA=(SID=hello42))) ``` is this sql error ? – Jeremy.l71 Jul 02 '19 at 07:05
  • It's likely that there is something wrong with accessing the database. Please make sure that all the credentials are correctly specified (the second **connect(..)** parameter) and the database is up and running. – käyrätorvi Jul 02 '19 at 07:38