-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_db.py
63 lines (46 loc) · 1.32 KB
/
get_db.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import psycopg2
# Replace these values with your PostgreSQL connection details
db_params = {
"dbname": "rocket2",
"user": "gs",
"password": "rocket",
"host": "localhost", # or your database host
"port": "5432", # or your database port
}
def retrieve_ecu_data(connection):
try:
cursor = connection.cursor()
# Select all rows from the 'ecu' table
cursor.execute("SELECT * FROM ecu;")
rows = cursor.fetchall()
# Print the retrieved data
for row in rows:
print(row)
except Exception as e:
print(f"Error: {e}")
finally:
cursor.close()
def retrieve_gse_data(connection):
try:
cursor = connection.cursor()
# Select all rows from the 'ecu' table
cursor.execute("SELECT * FROM gse;")
rows = cursor.fetchall()
# Print the retrieved data
for row in rows:
print(row)
except Exception as e:
print(f"Error: {e}")
finally:
cursor.close()
# Connect to the PostgreSQL database
try:
connection = psycopg2.connect(**db_params)
retrieve_ecu_data(connection)
print("GSE")
retrieve_gse_data(connection)
except psycopg2.Error as e:
print(f"Unable to connect to the database. Error: {e}")
finally:
if connection:
connection.close()