You are on page 1of 1

Program 19

Aim:
To write a python program to integrate SQL with python by importing the MySQL module to search an employee
number in table employee and display record, if employee number not found display appropriate message.

Program:
import mysql.connector
con=mysql.connector.connect(host="localhost",user="root",password="root",database="employee")
cur=con.cursor()
print("#"*40)
print("EMPLOYEE SEARCHING FROM")
print("#"*40)
print("\n\n")
ans='y'
while ans=='y':
Eno=int(input("Enter Employee number to search:"))
query="select * from employee where Eno={}".format(Eno)
cur.execute(query)
result=cur.fetchall()
if result!=None:
print("%10s"%"Eno","%20s"%"Name","%15s"%"Salary")
else:
print("Sorry! Employee number not found")
for row in result:
print("%10s"%row[0],"%20s"%row[1],"%15s"%row[2])
ans=input("Search more?(y/n)")

Result:
Thus the above python program to integrate SQL with python by importing the MySQL module to search an
employee number in table employee and display record, if employee number not found display appropriate message is
executed successfully and the output is verified.

You might also like