DB Connectivity Board
DB Connectivity Board
AR
Cur.execute(‘SELECT * FROM PASSENGERS’)
Recs=Cur.fetchall()
for R in Recs:
print(R[1])
cmpt-2021
CS M
2.
T- KU
PG A
DR
R EN
NA
[2022]
3. Consider the following table EMPLOYEE in a Database COMPANY :
Table : EMPLOYEE
E_ID NAME DEPT
H1001 Avneet AC
A1002 Rakesh HR
A1003 Amina AC
H1002 Simon HR
A1004 Pratik AC
Assume that the required library for establishing the connection between Python and MySQL is already
imported in the given Python code. Also assume that DB is the name of the database connection for the
given table EMPLOYEE stored in the database COMPANY.
Predict the output of the following Python code : 2
CUR=DB.cursor()
CUR.execute("USE COMPANY")
CUR.execute("SELECT * FROM EMPLOYEE WHERE DEPT = 'AC' ")
for i in range(2) :
R=CUR.fetchone()
print(R[0], R[1], sep ="#")
[COMPT 2022]
4.
AR
CS M
T- KU
PG A
DR
R EN
NA
[2023]
5.
AR
CS M
T- KU
PG A
DR
R EN
[2023]
NA
AR
7. The table Bookshop in MySQL contains the following attributes :
B_code- Integer
B_name- String
Qty -Integer
Price- Integer
CS M
Note the following to establish connectivity between Python and MySQL on a ‘localhost’
• Username is shop
• Password is Book
T- KU
• The table exists in a MySQL database named Bstore.
The code given below updates the records from the table Bookshop in MySQL. 3
Statement 1 to form the cursor object.
Statement 2 to write the query to display all the records from the table.
Statement 3 to read the complete result of the query into the object named B_Details, from the table
Bookshop in the database.
import mysql.connector as mysql
PG A
def Display_book():
mydb=mysql.connect(host="localhost",user="shop",passwd="Book",database="Bstore")
mycursor=___________ # Statement 1
DR
mycursor.execute("_________") # Statement 2
B_Details=__________ # Statement 3
for i in B_Details:
print(i)
[compt 2023]
EN
8.
R
NA
2024
9.
AR
CS M
T- KU
2024
10. Sangeeta wants to write a program in Python to delete the record of a candidate “Raman” from
the table named Placement in MySQL database, Agency:
The table Placement in MySQL contains the following attributes :
CName – String
Dept – String
PG A
Place – String
Salary – integer
Note the following to establish connectivity between Python and MySQL :
DR
Username – root
Password – job
Host – localhost
Help Sangeeta to write the program in Python for the above mentioned task.
Compt 2024
EN
11. Rahim wants to write a program in Python to insert the following record in the table named
Bank_Account in MySQL database, Bank :
Accno – integer
Cname – string
Atype – string
Amount – float
R
Host – localhost
The values of fields Accno, Cname, Atype and Amount have to be accepted from the user. Help
Rahim to write the program in Python. Compt 2024
13. fetchone() method fetches only one row in a ResultSet and returns a __________.
(a) Tuple
(b) List
(c) Dictionary
(d) String