Python Oracle DB Connect without Oracle Client

后端 未结 2 1207
囚心锁ツ
囚心锁ツ 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()
    
    0 讨论(0)
  • 2021-01-17 03:41

    It is not correct that java can connect to oracle without any oracle provided software.

    It needs a compatible version of ojdbc*.jar to connect. Similarly python's cx_oracle library needs oracle instant-client software from oracle to be installed.

    Instant client is free software and has a small footprint.

    0 讨论(0)
提交回复
热议问题