3

I am trying to build an application in python which will use Oracle Database installed in corporate server and the application which I am developing can be used in any local machine.

Is it possible to connect to oracle DB in Python without installing the oracle client in the local machine where the python application will be stored and executed?

Like in Java, we can use the jdbc thin driver to acheive the same, how it can be achieved in Python.

Any help is appreciated

Installing oracle client, connect is possible through cx_Oracle module. But in systems where the client is not installed, how can we connect to the DB.

Bishnu
  • 99
  • 1
  • 7
  • Perhaps https://pypi.org/project/JayDeBeApi/ - use Java JDBC driver in Python. You must still install JayDeBeApi module though (instead of Oracle Client), and download the driver file (JAR) from Oralce's site. – krokodilko Sep 04 '19 at 14:40
  • I tried to install this module but getting below error error: Microsoft Visual C++ 14.0 is required. – Bishnu Sep 04 '19 at 17:04
  • See this [article - python windows compilers](https://wiki.python.org/moin/WindowsCompilers). You are using Windows, so you need to install Microsoft C++ compiler which is compatible with your versionof Python. – krokodilko Sep 04 '19 at 19:14
  • python other functionalities are working perfectly fine. Even cx_Oracle module also working fine. Getting error only while installing the JayDeBeApi module. – Bishnu Sep 04 '19 at 19:33
  • If all the target machines are Windows, you can put the Oracle Instant Client libraries in the same directory as the cx_Oracle shared library. – Christopher Jones Sep 06 '19 at 05:06
  • But again it will not serve the intention. My intention is to connect to the Oracle DB without installing Oracle client even if it is instant client. – Bishnu Sep 07 '19 at 16:21

3 Answers3

6

You can use JDBC

"""
Connect from Python to Oracle via JDBC
Get JDBC-driver here: https://download.oracle.com/otn/utilities_drivers/jdbc/193/ojdbc8-full.tar.gz
Python 3.7.4
conda install -c conda-forge jaydebeapi==1.1.1 --force-reinstall -y
conda install -c conda-forge JPype1==0.6.3 --force-reinstall -y
"""
import jpype
import jaydebeapi

JHOME = jpype.getDefaultJVMPath()
jpype.startJVM(JHOME, '-Djava.class.path=/ojdbc8-full/ojdbc8.jar')
con = jaydebeapi.connect('oracle.jdbc.driver.OracleDriver',
                         'jdbc:oracle:thin:user/pass@host_ip:1521:SID')
cur = con.cursor()
cur.execute('select dummy from dual')
r = cur.fetchall()
print(r[0][0])
cur.close()
con.close()
Niels Jespersen
  • 410
  • 4
  • 16
  • 1
    this just substitutes one enormous dependency (java) for another (oci). If the target already has java, ok, but if you're trying to limit dependencies, this is definately a frying pan/fire situation. – Marc Jun 23 '21 at 17:10
2

It is not correct that java can connect to oracle without any oracle provided software.

It needs a compatible version of ojdbc*.jar to connect. Similarly python's cx_oracle library needs oracle instant-client software from oracle to be installed.

Instant client is free software and has a small footprint.

Sam
  • 404
  • 4
  • 7
0

Installing Oracle client is a huge pain. Could you instead create a Webservice to a system that does have OCI and then connect to it that way? This might end being a better solution rather than direct access.

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30985390) – Simas Joneliunas Feb 08 '22 at 08:04
  • I recommend against rhetoric questions in answers. They risk being misunderstood as not an answer at all. You are trying to answer the question at the top of this page, aren't you? Otherwise please delete this post. – Yunnosch Apr 03 '22 at 07:51