python interface
python interface
EX.NO.21
Aim:
Program:
import mysql.connector
mycon=mysql.connector.connect(host='localhost',user='root',passwd='root12345')
cursor=mycon.cursor()
st="use school;"
cursor.execute(st)
cursor.execute(st3)
cursor.execute(st4)
mycon.commit()
cursor.execute(st5)
cursor.execute(st6)
data=cursor.fetchall()
OUTPUT
Result:
EX.NO.22
Aim:
2. Perform all the operations with reference to table Employee through MySQL-Python
connectivity.
i)Write a python program to insert 5 records in Employee table. Take these 5 records as an input from
the user (One record at a time). Note the following to establish connectivity between Python and
MySQL: Username is root Password is 12345 The table exists in a MySQL database named company.
The table has five attributes (Emp_ID, Emp_Name, DOJ, Gender, Salary)
ii) Update name of employee in Employee table whose employee id is ‘E1001’ (Take name as an
input from the user).
EX.NO.23
AIM:
To Write a python program that display first 8 rows fetched from student table of MySQl database
student_dbl
Program:
import mysql.connector
mycon=mysql.connector.connect(host='localhost',user='root'
,passwd='root12345')
cursor=mycon.cursor()
st="use school;"
cursor.execute(st)
mycon.commit()
cursor.execute(st)
data=cursor.fetchmany(8)
print(row)
OUTPUT
(11, 'ATHANG', 12, 'A', 'MALE', 90)
AIM:
Write a python database connectivity program that deletes record from student table of database that
have name = Meena
Program:
import mysql.connector
mycon=mysql.connector.connect(host='localhost',user='root',passwd='root12345')
cursor=mycon.cursor()
st1="use school;"
cursor.execute(st1)
cursor.execute(st2)
mycon.commit()
cursor.execute(st3)
mycon.commit()
data=cursor.fetchall()
print(row)
mycon.close()
OUTPUT
(11, 'ATHANG', 12, 'A', 'MALE', 90)
(12, 'ATHARVA', 12, 'B', 'MALE', 80)
(13, 'ANJALI', 12, 'C', 'FEMALE', 78)
(15, 'MEENAKSHI', 12, 'B', 'FEMALE', 53)
(16, 'SUSHIL', 12, 'B', 'MALE', 40)
(17, 'SUMEDH', 12, 'A', 'MALE', 69)
(18, 'LUMBINI', 12, 'A', 'FEMALE', 77)
(19, 'LOKESH', 12, 'B', 'MALE', 88)
(20, 'SUJATA', 12, 'A', 'FEMALE', 98)