-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
36 lines (27 loc) · 850 Bytes
/
main.py
File metadata and controls
36 lines (27 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
from dotenv import load_dotenv
import oracledb
load_dotenv()
username = os.getenv("DB_USER")
password = os.getenv("DB_PASS")
host = os.getenv("DB_SERVER")
port = os.getenv("DB_PORT")
service_name = os.getenv("DB_SERVICE")
dsn = f"{host}:{port}/{service_name}"
def connect_to_oracle():
try:
print("Attempting Oracle connection with DSN:", dsn)
connection = oracledb.connect(user=username, password=password, dsn=dsn)
cursor = connection.cursor()
cursor.execute("SELECT * FROM v$version")
for row in cursor:
print(row)
return connection, cursor
except Exception as e:
print("Error connecting to Oracle:", e)
return None, None
if __name__ == "__main__":
conn, cursor = connect_to_oracle()
if conn:
cursor.close()
conn.close()