Hackerss.com

Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in
hackerss
hackerss

Posted on

Python How to connect to oracle database


#import the module
import cx_Oracle

#create a function
def connect_to_oracle():
    """
    Connect to Oracle database.

    Returns
    -------
    cx_Oracle.Connection
        Connection to Oracle database.
    """

    #connect to Oracle database
    connection = cx_Oracle.connect("username/[email protected]:port/sid")

    #return the connection
    return connection

#example
connection = connect_to_oracle()
#output
print(connection)  #<cx_Oracle.Connection object at 0x7f8b8d9a5e10>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)