Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- 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()
Add Comment
Please, Sign In to add comment