我有格式为
的连接字符串jdbc:oracle:thin:@(DESCRIPTION = (LOAD_BALANCE=ON)
(ADDRESS = (PROTOCOL = tcp)(HOST = aaa)(PORT = 1531))
(ADDRESS = (PROTOCOL = tcp)(HOST = bbb)(PORT = 1526))
(ADDRESS = (PROTOCOL = tcp)(HOST = ccc)(PORT = 1526))
(ADDRESS = (PROTOCOL = tcp)(HOST = ddd)(PORT = 1526))
(CONNECT_DATA = (SERVER=dedicated)(SERVICE_NAME=a.b.org))
)
如何使用cx_Oracle connect
connection = cx_Oracle.connect( .... )
使用上述指定格式的连接字符串?
答案 0 :(得分:1)
实际上很简单。您可以执行以下操作:
dsn = """(DESCRIPTION = (LOAD_BALANCE=ON)
(ADDRESS = (PROTOCOL = tcp)(HOST = aaa)(PORT = 1531))
(ADDRESS = (PROTOCOL = tcp)(HOST = bbb)(PORT = 1526))
(ADDRESS = (PROTOCOL = tcp)(HOST = ccc)(PORT = 1526))
(ADDRESS = (PROTOCOL = tcp)(HOST = ddd)(PORT = 1526))
(CONNECT_DATA = (SERVER=dedicated)(SERVICE_NAME=a.b.org))
)
"""
cx_Oracle.connect("user", "password", dsn)
有效地,您可以在tnsnames.ora文件中找到的任何连接字符串也可以作为dsn参数直接传递给cx_Oracle.connect。