Created
December 10, 2018 18:21
-
-
Save oldarmyc/bd0d4d6e097e0b9841eb68dcc833be91 to your computer and use it in GitHub Desktop.
Oracle example connection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
In order to connect to oracle the following packages will need to be installed from conda. | |
cx_oracle | |
oracle-instantclient | |
libaio | |
""" | |
# Import the library needed | |
import cx_Oracle | |
# Import config parser to read the ini file setup as a secret | |
import configparser | |
# Setup the credentials | |
config = configparser.ConfigParser() | |
config.read('/var/run/secrets/user_credentials/oracle_credentials') | |
# Define some variables read from secret that was defined as an ini file | |
username = config.get('default', 'username') | |
password = config.get('default', 'password') | |
uri = config.get('default', 'uri') | |
port = config.get('default', 'port') | |
# Create the connection and setup the cursor | |
conn = cx_Oracle.connect(f'{username}/{password}@//{uri}:{port}/XEPDB1') | |
cur = conn.cursor() | |
# Execute select statement and fetch all results | |
cur.execute("SELECT 'Hello World!' FROM dual") | |
res = cur.fetchall() | |
# Print results | |
print(res) | |
# Close the connection | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment