successful db connection
This commit is contained in:
24
main.py
24
main.py
@@ -1,6 +1,22 @@
|
||||
def main():
|
||||
print("Hello from dao3!")
|
||||
import psycopg2
|
||||
|
||||
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")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user