我正在尝试使用 Python 连接到 AWS 上的 Oracle SQL。我安装了 cx_Oracle,设置了 ORacle Instant Client 路径,但似乎无法找出主机和 service_name。我查了一些过去的帖子,用谷歌搜索,似乎找不到。抱歉,如果这很明显,谢谢您的时间
Python 脚本:
import cx_Oracle
username = 'Think I have this one done'
password = 'assuming this is just the password'
host = 'is this the endpoint?'
port = 'This one is figured out'
service_name = 'is this the endpoint?'
dsn = cx_Oracle.makedsn(host, port, service_name=service_name)
connection = cx_Oracle.connect(username, password, dsn)
cursor = connection.cursor()
query = "SELECT * FROM your_table"
cursor.execute(query)
for row in cursor:
print(row)
cursor.close()
connection.close()
我尝试过谷歌,检查教程,浏览堆栈溢出和其他资源。
我使用了oracle提供的python oracle db库,它不需要任何额外的设置。它包含模块的编译驱动部分。
注意:检查oracle数据库的入站规则并使用命令验证oracle服务器是否可达
telnet <host> <port>
参考: https://python-oracledb.readthedocs.io/en/latest/index.html