- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Oracle Database Connection in Python
Python can connect to oracle using a python package called cx_Oracle. Oracle is one of the famous and widely used database and python’s data processing features are leverages well using this connectivity. In this article we will see how we can connect to oracle database and query the DB.
We can use the below command to install the python package which can be used for establishing the connectivity.
pip install cx_Oracle
Connecting to Oracle
Now using this module we can connect to a oracle database which is accessible through the oracle service name. We create a cursor and execute the SQl query through the cursor for creating a table. All this is handled through a try and except structure to catch any exception or failure in database connectivity.
import cx_Oracle # Connecting to DB try: con = cx_Oracle.connect('username/password@servicename') cursor = con.cursor() #Creating a table cursor.execute("create table TableName(COL1 VARCHAR2(200),\COL2 NUMBER(8))") print("Table Created") except cx_Oracle.DatabaseError as e: print("Problem connecting to Oracle", e) # Close the all database operation finally: if cursor: cursor.close() if con: con.close()
Running the above code gives us the following result −
- Database Connection in Python
- How to create Database Connection in Perl?
- Extracting data from SAP HANA database and load to ORACLE database
- Database wars mssql server oracle plsql and mysql
- How to view storage configuration of Oracle database?
- How to limit Database Resources per Session in Oracle?
- MySqldb Connection in Python
- Difference between logical and physical standby database in the oracle
- How to identify recent WAIT events in a Oracle database ?
- Database Wars: MSSQL Server, Oracle PL/SQL and MySQL
- How to insert an image in to Oracle database using Java program?
- How to create a Stored procedure in Oracle database using JDBC API?
- How to drop a table from Oracle database using JDBC API?
- Which PHP function is used to disconnect from MySQL database connection?
- Write an example to establish MySQL database connection using PHP script?