23)To write a Python Program to integrate MYSQL
with Python by inserting records to Emptable and
display the records.
import [Link]
con=[Link] (host='localhost', username='root' ,password='root',database='STU')
if con.is_connected():
cur=[Link]()
opt='y'
while opt=='y':
No-int (input("Enter Roll Number: "))
Name=input ("Enter Name: ")
Age-input ("Enter Age:")
Fees=int (input ("Enter Fees: "))
Query="INSERT INTO EMP VALUES ({},'{}','{}',{})".format (No, Name, Age,Fees)
[Link] (Query)
[Link]()
print ("Record Stored Successfully")
opt-input("Do you want to add another student details (y/n):")
Query="SELECT FROM STU";
[Link] (Query)
data=[Link]()
for i in data:
print(i)
[Link]()
Output:
Enter Roll Number:8
Enter Name:vrund
Enter Age:17
Enter Fees:300
Record Stored Successfully
Do you want to add another student details(y/n):y
Enter Roll Number:9
Enter Name:het
Enter Age:16
Enter Fees:150
Record Stored Successfully
Do you want to add another student details(y/n):n
(8, ‘vrund’ , 17 , 300)
(9, ‘het’ , 16 , 150)
24)To write a Python Program to integrate MYSQL
with Python to search an student using Roll
number and display the record if present in already
existing table STU, if not display the appropriate
message.
import [Link]
con=[Link] (host='localhost',
username='root' ,password='root',database='STU')
if con.is_connected():
cur=[Link]()
print ("Welcome to student Search Screen”)
No=int(input("Enter the Roll number to search")
Query="SELECT FROM STU WHERE Roll number={}".format (No)
[Link](Query)
data=[Link]()
If data!=None:
else:
print (data)
print("Record not Found!")
[Link]()
Output:
Welcome to student Search Screen
Enter the Roll number to search:2
(2, 'sankalp',17 ,250 )
Welcome to student Search Screen
Enter the Roll number to search:404
Record not Found!
import [Link]
con=[Link] (host='localhost',
username='root' ,password='root',database='STU')
if con.is_connected():
cur=[Link]()
print (Welcome to student detail update Screen’)
No-int(input("Enter tha Roll number to Update:")) Ouery="SELECT FROM STU WHERE Roll number={}"
format (No)
[Link] (Query)
data=[Link]()
If data!=None:
else:
print ("Record found datails are: ")
print (data)
ans-input (Do you want to update the fees of the above student (y/n)?:)
If ans=='y' or ans=='Y':
New_Sal=int(input("Enter the new fees of the student:"))
Q1=UPDATE STU SET fees={} WHERE Roll number={}".format (New_Sal, No)
[Link](Q1)
[Link]()
print ("student fees Updated Successfully")
Q2="SELECT FROM STU"
[Link](Q2)
data=[Link]()
for i In data:
print(i)
print("Record not Found!")
Output:
Welcome to student detail update Screen
Enter the Roll number to search:3
Record found details are:
(3 , 'varun' , 18 , 350)
Do you want to update the fees of the above student (y/n)?:y
Enter the New fees of an student:300
Exployee Salary Updated Successfully
(3 , 'varun' , 18 ,300)