Python-data
Python-data

Reputation: 45

How to connect with oracle database?

I am using this code to connect with oracle database:

import cx_Oracle

conn_str = u"jbdc:oracle:thin:@****_***.**.com"
conn = cx_Oracle.connect(conn_str)
c = conn.cursor()

However, I am getting this error:

ORA-12560: TNS:protocol adapter error

How can I resolve it?

Thank you

Upvotes: 1

Views: 1281

Answers (1)

Anthony Tuininga
Anthony Tuininga

Reputation: 7096

You cannot use a JDBC thin connect string to connect with cx_Oracle (or the new python-oracledb). You must use either an alias found in a tnsnames.ora file, or the full connect descriptor (such as that found in a tnsnames.ora) file or an EZ+ Connect string. An example follows:

conn_str = "user/password@host:port/service_name"

With the new python-oracledb driver you can also do this:

import oracledb
conn = oracledb.connect(user="USER", password="PASSWORD", host="my_host",
                        port=1521, service_name="my_service")

See the documentation for more details.

Upvotes: 1

Related Questions