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?

- 176
- 1
- 11
-
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. – acutesoftware Sep 29 '15 at 05:56
2 Answers
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()

- 61
- 3
-
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? – user3379410 Sep 29 '15 at 08:07
-
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() – Rajesh Kanna Sep 29 '15 at 13:33
-
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. – user3379410 Oct 05 '15 at 01:03
-
you have to install instance client.But its not harm to be install at Production environment. https://docs.oracle.com/database/121/JJDBC/instclnt.htm#JJDBC28248 – Rajesh Kanna Oct 06 '15 at 20:00
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.

- 6,207
- 5
- 44
- 66