Interface Python with SQL Class 12 Computer Science Exam Questions

Exam Questions Class 12

Please refer to Computer Science For Interface Python with SQL Class 12 Computer Science Exam Questions provided below. These questions and answers for Class 12 Computer Science have been designed based on the past trend of questions and important topics in your class 12 Computer Science books. You should go through all Class 12 Computer Science Important Questions provided by our teachers which will help you to get more marks in upcoming exams.

Class 12 Computer Science Exam Questions Interface Python with SQL

Very Short Answer Type Questions :

Question. In the following connection string: Identify the elements : (assume ‘admin’ is password) connect(__<<1>> = “localhost”,__<<2>> =‟ root‟, <<3>>=”admin”)
Answer: <<1>> = host, <<2>> = user, <<3> = passwd

Question. Which function is used to clean connection environment and close connection?
Answer: con.close() where con is the name of connection object.

Question. Name of connector/driver used to establish bridge between Python and MySQL?
Answer: mysql.connector

Question. Which command of Python is used to install mysql.connector driver in python IDLE?
Answer: pip install mysql.connector

Question. What do you mean by Database connectivity?
Answer: Database connectivity refers to connection/communication between front-end applications like Python, Java etc. to Back-end Applications like MySQL, SQL Server etc.

Question. Which of the component/object which act as a container to hold all the data returned from the query and from there we can fetch data one at a time?
Answer: Cursor

Question. What is Result set?
Answer: Result set refers the logical set records fetched from the database by executing a query.

Question. Identify the correct statement to create cursor:
import mysql.connector as msq
con = msq.connect( #Connection String ) # Assuming all parameter required as passed
mycursor =
a. con.cursor()
b. con.create_cursor()
c. con.open_cursor()
d. con.get_cursor()
Ans a. con.cursor()

Question. Which function of connection is used to check whether connection to mysql is successfully done or not?
Answer: con.is_connected() where con is name of connection object.

Question. Which command is used to add database connection package in the Python program?
Answer: import mysql.connector

Question: write the steps of connectivity between SQL and Python
Answer: import,connect,cursor,execute

Interface Python with SQL Class 12 Computer Science Exam Questions

Question: What is result set? Explain with example.
Answer: Fetching rows or columns from result sets in Python. The fetch functions in the ibm_db API can iterate through the result set. If your result set includes columns that contain large data (such as BLOB or CLOB data), you can retrieve the data on a column-by-column basis to avoid large memory usage.

Question: Write python-mysql connectivity to retrieve all the data of table student.
Answer:-import mysql.connector
mydb=mysql.connector.connect(user=”root”,host=”localhost”,passwd=”123″,database=”inservice”)
mycursor=mydb.cursor()
mycursor.execute(“select * from student”)
for x in mycursor:
print(x)

Question: Use of functions in connectivity – INSERT, UPDATE, DELETE, ROLLBACK
Answer:

Interface Python with SQL Class 12 Computer Science Exam Questions

Question: Write code for database connectivity
Answer: # importing the module
import mysql.connector
# opening a database connection
conn = mysql.connector.connect (“localhost”,”testprog”,”stud”,”PYDB”)
# define a cursor object
mycursor = conn.cursor
# drop table if exists
mycursor.execute(“DROP TABLE IF EXISTS STUDENT”)
# query
sql = “CREATE TABLE STUDENT (NAME CHAR(30) NOT NULL, CLASS CHAR(5), AGE INT,
GENDER CHAR(8), MARKS INT)”
# execute query
cursor.execute(sql)
# close object
cursor.close()
# close connection
conn.close()

Question: What is database.
Answer: The database is a collection of organized information that can easily be used, managed, update, and they are classified according to their organizational approach.

Question: Write command to install connector.
Answer: pip install mysql-connector-python

Question: Write command to import connector.
Answer: import mysql.connector

Question: Which method is used to retrieve all rows and single row?
Answer: Fetchall(),fetchone()