[Type A] Chapter 16 Sumita Arora Solutions | Class 12 Computer Science

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.

Q1: What are the steps to connect to a database from with Java – Python application?
After having MySQLdb installed on your local machine run the below command
$ import MySQLdb

Now opening the Open database connection 
$ db = MySQLdb.connect("localhost","testuser","test123","TESTDB")

Now creating a cursor to the active database for operation
$ cursor = db.cursor() 
$ data = cursor.fetchone() 
$ print ("Database version : %s ", % data)
Q2: Write code to connect to a MySQL database namely School and then fetch all those records from table Student where grade is ‘A’.
$ import mysql.connector as sql    #importing the package
$ obj = sql.connect(host ="localhost", user="root", passwrd="MYpass", database="test")
$ cursor = obj.cursor()  # creating the cursor the database object
$ cusor.execute("SELECT * FROM Student WHERE grade is 'A'")  # executing the query
Q3: Predict the output of the following code:

Import mysql.connector
db=mysql.connector.connect (_____)
cursor = db.cursor( )
Sql1 = “update category set name= ‘%s’ WHERE ID= %s”%(.’CSS’,2)
cursor.execute(sql1)
db.commit()
print(“Rows affected:”,cursor.rowcount)
db.close()
The above code will print 0 as no row has been fetched yet.
But beyond that an update command will execute changing name to CSS where id is 2.
Q4: Explain what the following query will do?

Import.mysql.connector
db=mysql.connector.connect(____)
Cursor = db.cursor()
person_id =input(“Enter required person id”)
lastname = input (“Enter required lastname”)
db.execute(“INSERT INTO staff(person_id,lastname) VALUES({},’{}’)”.
format(person_id, lastname))
db.commit()
db.close()

Q5: Explain what the following query will do?

import mysql.connector
db = mysql.connector.connect(……..)
Cursor = db.cursor()
db.execute(“SELECT*FROM staff WHERE person_id in{}”,format((1,3,4)))
db.commit()
db.close()

The above code will fetch all those records from staff where person_id is either of 1, 3, 4 in the database.

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