Files
DAO3/main.py

23 lines
529 B
Python
Raw Normal View History

2026-09-01 22:12:58 +01:00
import psycopg2
2026-08-31 23:16:53 +01:00
2026-09-01 22:12:58 +01:00
connection = psycopg2.connect(
user="postgres",
host="192.168.10.102",
port="5433",
database="abs"
)
try:
cursor = connection.cursor()
cursor.execute("SELECT version();")
record = cursor.fetchone()
print("You are connected to - ", record, "\n")
except (Exception, psycopg2.Error) as error:
print("Error while connecting to PostgreSQL", error)
finally:
if connection:
cursor.close()
connection.close()
print("PostgreSQL connection is closed")
2026-08-31 23:16:53 +01:00