Guest User

Untitled

a guest
Dec 10th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. """
  2. In order to connect to oracle the following packages will need to be installed from conda.
  3.  
  4. cx_oracle
  5. oracle-instantclient
  6. libaio
  7. """
  8. # Import the library needed
  9. import cx_Oracle
  10.  
  11.  
  12. # Import config parser to read the ini file setup as a secret
  13. import configparser
  14.  
  15.  
  16. # Setup the credentials
  17. config = configparser.ConfigParser()
  18. config.read('/var/run/secrets/user_credentials/oracle_credentials')
  19.  
  20. # Define some variables read from secret that was defined as an ini file
  21. username = config.get('default', 'username')
  22. password = config.get('default', 'password')
  23. uri = config.get('default', 'uri')
  24. port = config.get('default', 'port')
  25.  
  26. # Create the connection and setup the cursor
  27. conn = cx_Oracle.connect(f'{username}/{password}@//{uri}:{port}/XEPDB1')
  28. cur = conn.cursor()
  29.  
  30. # Execute select statement and fetch all results
  31. cur.execute("SELECT 'Hello World!' FROM dual")
  32. res = cur.fetchall()
  33.  
  34. # Print results
  35. print(res)
  36.  
  37. # Close the connection
  38. conn.close()
Add Comment
Please, Sign In to add comment