-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata-oraclepush.py
More file actions
23 lines (21 loc) · 889 Bytes
/
data-oraclepush.py
File metadata and controls
23 lines (21 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import oracledb
import csv
from dotenv import load_dotenv
import os
load_dotenv()
dsn = '(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host='+os.getenv("ora.host")+'))(connect_data=(service_name='+os.getenv("ora.service")+'))(security=(ssl_server_dn_match=yes)))'
connection = oracledb.connect(user=os.getenv("ora.user"),
password=os.getenv("ora.password"), dsn=dsn)
cursor = connection.cursor()
csv_file = "data.csv"
rows = []
with open(csv_file, newline="") as f:
reader = csv.DictReader(f)
for row in reader:
rows.append((int(row["id"]), row["name"], row["ssn"], row["dob"], row["card"], row["exp"]))
sql = """INSERT INTO VOLTAGE.data (id, name, ssn, dob, card, exp) VALUES (:1, :2, :3, :4, :5, :6)"""
cursor.executemany(sql, rows)
connection.commit()
print(f"Inserted {cursor.rowcount} rows")
cursor.close()
connection.close()