-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimple_db_test.py
More file actions
39 lines (30 loc) · 946 Bytes
/
Copy pathsimple_db_test.py
File metadata and controls
39 lines (30 loc) · 946 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
37
38
39
import psycopg2
import sys
# Database connection parameters
params = {
'host': 'localhost',
'port': 5432,
'database': 'litigation_simulator',
'user': 'postgres',
'password': 'Teqifjarobt$$44'
}
print("Attempting to connect to PostgreSQL database...")
print(f"Connection parameters: host={params['host']}, port={params['port']}, db={params['database']}, user={params['user']}")
try:
# Establish connection
conn = psycopg2.connect(**params)
# Create a cursor
cur = conn.cursor()
# Execute a test query
cur.execute("SELECT version();")
# Fetch the result
version = cur.fetchone()[0]
print("Connection successful!")
print(f"PostgreSQL version: {version}")
# Close cursor and connection
cur.close()
conn.close()
print("Connection closed.")
except Exception as e:
print(f"Error: {e}")
sys.exit(1)