繁体   English   中英

通过 python 连接到 oracle DB

[英]Connecting to oracle DB through python

我正在尝试使用 python 通过 PyCharm 连接到 oracle db,下面是我的代码和连接详细信息的屏幕截图

代码:

import cx_Oracle   
try:
    conn = cx_Oracle.connect('sys/123@//localhost:1521/XEPDB1')    
except:
    print("Connection Error")
    exit()

Output

连接错误在此处输入图像描述

有多种方法可以做到这一点,使用 SID 或服务名称

识别码:

import cx_Oracle
dsn_tns = cx_Oracle.makedsn('server', 'port', 'sid')
conn = cx_Oracle.connect(user='username', password='password', dsn=dsn_tns)

服务名称:-

import cx_Oracle
dsn_tns = cx_Oracle.makedsn('server', 'port', service_name='service_name')
conn = cx_Oracle.connect(user='username', password='password', dsn=dsn_tns)

您可以在此处参考此文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM