5
Question Consider the following table STUDENT.
| NO | NAME | AGE | DEPARTMENT | FEE | SEX |
|---|---|---|---|---|---|
| 1 | PANKAJ | 24 | COMPUTER | 120 | M |
| 2 | SHALINI | 21 | HISTORY | 200 | F |
| 3 | SANJAY | 22 | HINDI | 300 | M |
| 4 | SUDHA | 25 | HISTORY | 400 | F |
Write a Python code to search a record as per given NO (number) using MySQL connectivity and print the data.
import mysql.connector
mydb = mysql.connector.connect(host = "localhost",
user = "root",
passwd = "tiger",
database = "kboat_cbse_12")
mycursor = mydb.cursor()
NO = int(input("Enter the number to search: "))
mycursor.execute("SELECT * FROM STUDENT WHERE NO = {}".format(NO))
myrecord = mycursor.fetchone()
if myrecord != None:
print(myrecord)
else:
print("No such student found")Enter the number to search: 2
(2, 'SHALINI', 21, 'HISTORY', 200, 'F')