没有Oracle Client的Python Oracle DB Connect [英] Python Oracle DB Connect without Oracle Client

查看:307
本文介绍了没有Oracle Client的Python Oracle DB Connect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python构建一个应用程序,该应用程序将使用安装在公司服务器中的Oracle数据库,并且我正在开发的应用程序可以在任何本地计算机上使用.

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.

是否可以使用Python连接到oracle DB,而无需在将要存储和执行python应用程序的本地计算机上安装oracle客户端?

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?

就像Java中一样,我们可以使用jdbc瘦驱动程序来达到相同的效果,如何在Python中实现它.

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

感谢您的帮助

安装oracle客户端,可以通过cx_Oracle模块进行连接. 但是在未安装客户端的系统中,我们如何连接到数据库.

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.

推荐答案

您可以使用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()

这篇关于没有Oracle Client的Python Oracle DB Connect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆