-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEraseDatabase.py
43 lines (36 loc) · 1.25 KB
/
EraseDatabase.py
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
40
41
42
43
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 16 00:17:40 2022
@author: f.ozdemir
"""
import psycopg2
from psycopg2 import Error
try:
# Connect to an existing database
connection = psycopg2.connect(user="postgres",
password="4874651",
host="127.0.0.1",
port="5432",
database="IKU-OBE-alfa")
# Create a cursor to perform database operations
cursor = connection.cursor()
# Print PostgreSQL details
print("PostgreSQL server information")
print(connection.get_dsn_parameters(), "\n")
# Executing a SQL query
cursor.execute("SELECT version();")
# Fetch result
record = cursor.fetchone()
print("You are connected to - ", record, "\n")
except (Exception, Error) as error:
print("Error while connecting to PostgreSQL", error)
finally:
cursor.execute("drop table grade;\
drop table copo;\
drop table questweight;\
drop table student;\
drop table assesweight;\
drop table course;")
connection.commit()
cursor.close()
connection.close()