SQL Connector
SQL Connector
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 mysql.connector
con=mysql.connector.connect (host='localhost',
username='root' ,password='root',database='STU')
if con.is_connected():
cur=con.cursor()
print ("Welcome to student Search Screen”)
No=int(input("Enter the Roll number to search")
Query="SELECT FROM STU WHERE Roll number={}".format (No)
cur.execute(Query)
data=cur.fetchone()
If data!=None:
else:
print (data)
print("Record not Found!")
con.close()
Output:
Welcome to student Search Screen
Enter the Roll number to search:2
(2, 'sankalp',17 ,250 )
Output: