1

I am writing a Python script to fetch and update some data on a remote oracle database from a Linux server. I would like to know how can I connect to remote oracle database from the server.
Do I necessarily need to have an oracle client installed on my server or any connector can be used for the same?
And also if I use cx_Oracle module in Python, is there any dependency that has to be fulfilled for making it work?

1
  • You need the client on your machine, but you probably wont need the oracle client installed separately on the server, as the oracle server is already running there. Commented Sep 29, 2015 at 5:56

2 Answers 2

1

You have to Install Instance_client for cx_oracle driver to interact with remote oracle server

http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html.

Use SQLAlchemy (Object Relational Mapper) to make the connection and interact with Oracle Database.

The below code you can refer for oracle DB connection.

from sqlalchemy import create_engine

from sqlalchemy.orm import sessionmaker

engine = create_engine('oracle+cx_oracle://test_user:test_user@ORACSG')

session_factory = sessionmaker(bind=engine, autoflush=False)

session = session_factory()

res = session.execute("select * from emp");

print res.fetchall()

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

4 Comments

I have installed instant client and able to import cx_Oracle in the script. Now to connect to db do we necessarily have to use a connector (SQLAlchemy, as you mentioned) or it can be done without it?
You can connect without SqlAlchemy .. >>> ip = '192.168.0.1' >>> port = 1521 >>> SID = 'YOURSIDHERE' >>> dsn_tns = cx_Oracle.makedsn(ip, port, SID) >>> conn = cx_Oracle.connect('username', 'password', dsn_tns) >>> curs = conn.cursor() >>> curs.execute('select * from emp') >>> print curs.description for row in curs: print row conn.close()
If we use java to write the code (therefore, jdbc module), do we still necessarily need to install an instant client or any other oracle client or JDBC is sufficient for that as well? What I want is, the user need not able to install oracle client on their side. If JDBC does it, excellent. If not, please let me know if its possible for I am trying to do.
you have to install instance client.But its not harm to be install at Production environment. docs.oracle.com/database/121/JJDBC/instclnt.htm#JJDBC28248
0

Yes, you definitely need to install an Oracle Client, it even says so in cx_oracle readme.txt. Another recommendation you can find there is installing an oracle instant client, which is the minimal installation needed to communicate with Oracle, and is the simplest to use. Other dependencies can usually be found in the readme.txt file, and should be the first place to look for these details.

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.