-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPDBC11.py
26 lines (25 loc) · 856 Bytes
/
PDBC11.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
#Python program to fetch the employee data from mysql database and print on the console
import pymysql
try:
con=pymysql.connect(host='localhost',user='root',password='root123',database='python')
cursor=con.cursor()
query="select * from employees"
cursor.execute(query)
n=int(input("Enter the number of Employees for which data is to be fetched:"))
data=cursor.fetchmany(n)
for d in data:
print("Employee Number:",d[0])
print("Employee Name:",d[1])
print("Employee Salary:",d[2])
print("Employee Address:",d[3])
print()
print("Employee Data Fetched SuccessFully for",n,"Employees.")
except pymysql.DatabaseError as m:
if con!=None:
con.rollback()
print("There is a problem:",m)
finally:
if cursor:
cursor.close()
if con:
con.close()