【问题标题】:Python connect to JDBC thin custom url OraclePython 连接到 JDBC 瘦自定义 url Oracle
【发布时间】:2020-09-30 13:09:38
【问题描述】:

我有一个 Oracle 数据库。只能通过自定义 jdbc URL 连接数据库:jdbc:oracle:thin:@servername:port/service_name。其中驱动程序 = 'Oracle in OraClient12Home_x64_1'

现在我需要使用 python 连接到数据库。

我尝试过 pyodbc 和 cx_oracle,似乎都没有。

这是我尝试过的:

pyodbc:

dbq = servername:port/service_name

conn_string = fr'DRIVER={driver};DBQ={dbq};UID={uid};PWD={pwd};

connection = pyodbc.connect(dsn)

cx_Oracle:

dsn = cx_Oracle.makedsn('@servername','port',service_name='service_name')

connection = cx_Oracle.connect(dsn)

我继续收到 TNS:标识符错误或 TNS 适配器错误。

有什么想法吗?

【问题讨论】:

    标签: python oracle pyodbc cx-oracle


    【解决方案1】:

    这是关于从 JDBC 连接字符串映射的 cx_Oracle 文档:JDBC and Oracle SQL Developer Connection Strings

    尝试不使用您显示的“@”:

    dsn = cx_Oracle.makedsn('example.com','1521',service_name='mydbservice')
    
    connection = cx_Oracle.connect(username, password, dsn)
    

    替换你的实际值

    或者干脆使用

    connection = cx_Oracle.connect(username, password, 'example.com:1521/mydbservice')
    

    【讨论】:

      猜你喜欢
      • 2019-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-17
      • 2016-03-17
      • 2019-11-10
      • 1970-01-01
      相关资源
      最近更新 更多