[Type B] Chapter 16 | Python application to obtain a search criteria from user and then fetch records based on that from empl table.(given in chapter 13)

Here is class 12 computer science Unit 16 solutions for Sumita Arora back exercise assignment. Below includes both textual and video solutions wherever required. View all the answers in assignment for chapter 16 and for all chapters here.

Sumita Arora Solutions for all lessons here.

Question 3: Design a Python application to obtain a search criteria from user and then fetch  records based on that from empl table.(given in chapter 13)
$ import mysql.connector as sql         #import the sql package

$ obj = sql.connect(host="localhost", user="root",
passwd="Pass", database="menagerie")         #creating the object

$ cursor = obj.cursor() #create a cursor object

$ col = input('Enter the column name : ')       # search criteria
$ val = input('Enter value : ')

$ cursor.execute("SELECT * FROM Empl WHERE {} ='{}'.format(col, val)") #execute the query

$ data = cursor.fetchall() #return all rows of result

$ print(data) # print all the rows

Clear Doubts with Computer Tutor
In case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in

You cannot copy content of this page