方法一:
import cx_Oracle
host = "host"
account = "account"
password = "password"
service_name = "service_name"
connect = cx_Oracle.connect(account + r'/' + password + '@' + host + r'/' + service_name, encoding="UTF-8")
方法二:
import cx_Oracle
host = "host"
account = "account"
password = "password"
service_name = "service_name"
tns = cx_Oracle.makedsn(host, 1521, service_name)
connect = cx_Oracle.connect(account, password, tns, encoding="UTF-8")
本文介绍了两种使用Python cx_Oracle库连接Oracle数据库的方法。第一种直接通过账号、密码、主机和服务名进行连接;第二种则通过创建tnsnames.ora文件中的条目来实现连接,更加灵活且易于维护。
283

被折叠的 条评论
为什么被折叠?



