Guest User

Untitled

a guest
Oct 27th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. import psycopg2
  2. from psycopg2 import Error
  3. try:
  4. connection = psycopg2.connect(user = "postgres",
  5. password = "password",
  6. host = "127.0.0.1",
  7. port = "5432",
  8. database = "syapse")
  9. cursor = connection.cursor()
  10. # Print PostgreSQL Connection properties
  11. print ( connection.get_dsn_parameters(),"\n")
  12. # Print PostgreSQL version
  13. cursor.execute("SELECT version();")
  14. record = cursor.fetchone()
  15. print("You are connected to - ", record,"\n")
  16. except (Exception, psycopg2.DatabaseError) as error :
  17. print ("Error while connecting to PostgreSQL", error)
  18. finally:
  19. #closing database connection.
  20. if(connection):
  21. cursor.close()
  22. connection.close()
  23. print("PostgreSQL connection is closed")
Add Comment
Please, Sign In to add comment