-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdb_connection_module.py
More file actions
31 lines (27 loc) · 1.05 KB
/
db_connection_module.py
File metadata and controls
31 lines (27 loc) · 1.05 KB
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
import psycopg2
try:
connection = psycopg2.connect(user = "postgres",
password = "nighty32",
host = "127.0.0.1",
port = "5432",
database = "postgres") # these could all be in a separate module as CONST values
cursor = connection.cursor()
# Print PostgreSQL Connection properties
#print ( connection.get_dsn_parameters(),"\n")
# Print PostgreSQL version
#cursor.execute("SELECT version();")
"""Run the query and fetch records"""
cursor.execute("SELECT url,username,password FROM automation_data;")
#record = cursor.fetchone()
record = cursor.fetchall()
#print record
#print (record[0])
print (record[1])
except (Exception, psycopg2.Error) as error :
print ("Error while connecting to PostgreSQL", error)
finally:
#closing database connection.
if(connection):
cursor.close()
connection.close()
print("PostgreSQL connection is closed")