---
title: "How can I connect to the Oracle database by ConnectorX Python?"  
description: "How can I connect to the Oracle database by ConnectorX Python?"  
author: "Sandra Emily"  
published: 2023-08-22  
updated: 2023-08-23  
canonical: https://www.mindstick.com/forum/159647/how-can-i-connect-to-the-oracle-database-by-connectorx-python  
category: "database"  
tags: ["database connection", "python", "oracle"]  
reading_time: 1 minute  

---

# How can I connect to the Oracle database by ConnectorX Python?

How can I [connect](https://www.mindstick.com/articles/12810/how-to-connect-tablet-to-external-monitor-or-flat-screen-tv-using-computer-adapters) to the [Oracle database](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database) by ConnectorX [Python](https://www.mindstick.com/articles/75378/simple-yet-useful-tips-when-using-python)?

## Replies

### Reply by Aryan Kumar

To connect to the [Oracle](https://www.mindstick.com/articles/13016/alter-table-statement-or-command-in-oracle) [database](https://www.mindstick.com/articles/12226/use-of-database-in-sencha-extjs-and-insert-record-from-user-form-using-ajax) by Connector X Python, you can follow these steps:

1. Install the cx_Oracle module.

```plaintext
pip install cx_Oracle
```

1. Create a connection string. The connection string specifies the connection information, such as the database hostname, port number, username, and password.

```plaintext
connection_string = 'oracle://username:password@hostname:port/database_name'
```

1. Create a connection object. The connection object is used to connect to the database.

```plaintext
connection = cx_Oracle.connect(connection_string)
```

1. Execute a SQL statement. The SQL statement is executed using the connection object.

```plaintext
cursor = connection.cursor()
cursor.execute('SELECT * FROM table_name')
```

1. Fetch the results. The results of the SQL statement are fetched using the cursor object.

```plaintext
for row in cursor:
  print(row)
```

1. Close the connection. The connection is closed to release the resources.

```plaintext
cursor.close()
connection.close()
```

Here is an example of a Python code that connects to the Oracle database and executes a SQL statement:

Python

```plaintext
import cx_Oracle

connection_string = 'oracle://username:password@hostname:port/database_name'

connection = cx_Oracle.connect(connection_string)

cursor = connection.cursor()

cursor.execute('SELECT * FROM table_name')

for row in cursor:
  print(row)

cursor.close()
connection.close()
```


---

Original Source: https://www.mindstick.com/forum/159647/how-can-i-connect-to-the-oracle-database-by-connectorx-python

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
