Python Oracle DB Connect without Oracle Client

给你一囗甜甜゛ 提交于 2020-01-25 06:51:12

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/57789704/python-oracle-db-connect-without-oracle-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!