Python Oracle DB Connect without Oracle Client

后端 未结 2 1206
囚心锁ツ
囚心锁ツ 2021-01-17 03:15

I am trying to build an application in python which will use Oracle Database installed in corporate server and the application which I am developing can be used in any local

2条回答
  •  执笔经年
    2021-01-17 03:36

    You can use JDBC

    """
    Connect from Python to Oracle via JDBC
    Get JDBC-driver here: https://download.oracle.com/otn/utilities_drivers/jdbc/193/ojdbc8-full.tar.gz
    Python 3.7.4
    conda install -c conda-forge jaydebeapi==1.1.1 --force-reinstall -y
    conda install -c conda-forge JPype1==0.6.3 --force-reinstall -y
    """
    import jpype
    import jaydebeapi
    
    JHOME = jpype.getDefaultJVMPath()
    jpype.startJVM(JHOME, '-Djava.class.path=/ojdbc8-full/ojdbc8.jar')
    con = jaydebeapi.connect('oracle.jdbc.driver.OracleDriver',
                             'jdbc:oracle:thin:user/pass@host_ip:1521:SID')
    cur = con.cursor()
    cur.execute('select dummy from dual')
    r = cur.fetchall()
    print(r[0][0])
    cur.close()
    con.close()
    

提交回复
热议问题