Interface Python with MySQL || Type A || Sumita Arora || Class 12 || Computer science || Information practices || Solution

 


Q 1 = What are the steps to connect to a database from with Java application ? .


Q 2 = Write code to connect to a MYSQL database namely School and then fetch all those records from table Student where grade is 'A'.



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()



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.connectar.connect(….)

cursor = db.cursor()

db.execute("SELECT * FROM staff WHERE person_id in {}".format((1,3,4)))

db.commit()

db.close()

2 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post