3

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?

0

2 Answers 2

4

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)

Sign up to request clarification or add additional context in comments.

Comments

4

This way should work

  conn = jaydebeapi.connect('oracle.jdbc.driver.OracleDriver','jdbc:oracle:thin:user/password@//DB_HOST_IP:1521/DB_NAME')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.