This sample code is used to connect in Python to Oracle SID.
import jpype
import jaydebeapi
jHome = jpype.getDefaultJVMPath()
jpype.startJVM(jHome, '-Djava.class.path=/path/to/ojdbc6.jar')
conn = jaydebeapi.connect('oracle.jdbc.driver.OracleDriver','jdbc:oracle:thin:user/password@DB_HOST_IP:1521:DB_NAME')
How can we connect to Oracle Service Name?
Regarding your connection string, you could use TNS
syntax ( read on, here ), as opposed to host:port:sid
syntax you're using now. In that case you would describe SERVICE_NAME
inside CONNECT_DATA
, as follows:
jaydebeapi.connect('oracle.jdbc.driver.OracleDriver','[MYUSER]/[MYPASS]@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=[MYHOST])(PORT=1521))(CONNECT_DATA=(SERVER=dedicated) (SERVICE_NAME=[MYSERVICENAME])))')
By the way - you could also use cx_Oracle to connect to oracle - no java
hassle. (just a suggestion)
这种方式应该有效
conn = jaydebeapi.connect('oracle.jdbc.driver.OracleDriver','jdbc:oracle:thin:user/password@//DB_HOST_IP:1521/DB_NAME')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.