Last active
October 7, 2019 12:06
-
-
Save Rizwan-Hasan/ec83aab4d81fdfc6e29e7a1017dd704d to your computer and use it in GitHub Desktop.
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
import cx_Oracle | |
def main(): | |
# Variables | |
username: str = "HR" | |
password: str = "<YOUR_PASSWORD>" | |
host: str = "localhost" | |
service: str = "XE" | |
# Connection establishing | |
connection = None | |
try: | |
connection = cx_Oracle.connect( | |
username, | |
password, | |
"{0}/{1}".format(host, service) | |
) | |
print("Connection successful") | |
except cx_Oracle.DatabaseError as e: | |
print(e) | |
# Executing DML | |
countryCode: str = "BD" | |
countryName: str = "Bangladesh" | |
regionID: int = 3 | |
cursor = connection.cursor() | |
cursor.execute( | |
"""INSERT INTO COUNTRIES | |
(COUNTRY_ID, COUNTRY_NAME, REGION_ID) | |
VALUES (:cCode, :cName, :rId)""", | |
cCode=countryCode, cName=countryName, rId=regionID | |
) | |
connection.commit() | |
print("Insertion successful") | |
connection.close() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment