CBSE Class 12 Computer Science Question 35 of 43

Practice Paper — Question 6

Back to all questions
6
Question

Question 29(b)

Write a Python code to insert a new record as per given table Student (No, Name, Age, Department, Fee, Sex) using MySQL connectivity.

Solution
import mysql.connector
mydb = mysql.connector.connect(host = "localhost", 
                                user = "root", 
                                passwd = "kboat123", 
                                database = "kboat_cbse_12")
mycursor = mydb.cursor()
mycursor.execute("INSERT INTO STUDENT VALUES(5, 'ANANYA', 23, 'COMPUTER', 450, 'F')")
mydb.commit()
print("Records added")
mydb.close()
Output
Records added
Answer