How to connect to your FREE Autonomous Database using Python from Cloud Shell?

 

Image for post
Cloud Shell open
$ oci db autonomous-database generate-wallet --autonomous-database-id ocid1.autonomousdatabase.oc1.eu-frankfurt-1.abtheljtcwfhy5ohok66arn6ngrpqdigvq7bzcpygtfnkbldvgtk4rv3xhtq --file wallet.zip --password My_Strong_Pa55word$ unzip wallet.zip
$ pwd$ export TNS_ADMIN=/home/loic_lefev$ sed -i 's/?\/network\/admin/$TNS_ADMIN/' sqlnet.ora
$ pip3 install --user cx_Oracle
import cx_Oracle
def connect():
connection = cx_Oracle.connect("dragon", "My_Strong_Pa55word", "dragon_tp")
return connection

def selectdate(connection):
with connection:
cursor = connection.cursor()
result = cursor.execute('''select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual''')
data = result.fetchone()
print("Date is " + data[0])

if __name__ == '__main__':
connection = connect()
selectdate(connection)
$ python3 test.py
Date is 2020-09-27 13:46:02
Image for post
Oracle Cloud Shell running a python script that connects to an Always Free Autonomous Transaction Processing database.

Comments

Popular posts from this blog

Flutter for Single-Page Scrollable Websites with Navigator 2.0

A Data Science Portfolio is More Valuable than a Resume

Better File Storage in Oracle Cloud