Peter has created a table named Account in MySQL database, SCHOOL, having following structure:
Stud_id – integer
Sname – string
Class – string
Fees – float
Help him in writing a Python program to display records of those students whose fees is less than 5000.
Note the following to establish connectivity between Python and MySQL: Username – admin, Password – root, Host – localhost
import mysql.connector
mydb = mysql.connector.connect(host='localhost', user='admin', password='root', database='SCHOOL')
if mydb.is_connected():
mycur = mydb.cursor()
mycur.execute('SELECT * FROM Account WHERE Fees < 5000')
rec = mycur.fetchone()
while rec is not None:
print(rec)
rec = mycur.fetchone()
mydb.close()