*******************NAME-ANIKET.
K - I2- 39******************
Experiment No.: 11 C
Aim: Write Python program to understand database connectivity with DML.
Program Code:
import [Link]
db= [Link](host="localhost", user="aniket",
passwd="password123")
cursor1= [Link]()
print(db)
[Link]("create database company ")
[Link]("show databases")
print("Databases: ")
for r in cursor1:
print(r)
db1= [Link](host="localhost", user="aniket",
passwd="password123",database="company")
cursor2=[Link]()
[Link]("create table employee(Name varchar(20),Age int(10),Salary
int(20))")
print()
print("Tables: ")
[Link]("show tables")
for r in cursor2:
print(r)
a="insert into employee(Name,Age,Salary) values(%s,%s,%s)"
b=[('Ajay',24,10000),('Sonali',22,15000),('Raj',25,20000),('Diya',24,10000),
('Ganesh',23,15000)]
[Link](a,b)
[Link]()
[Link]("select * from employee")
print()
print("Table contain: ")
m=[Link]()
for r in m:
print(r)
[Link]("select name,age from employee where salary=10000")
print()
print("Employees having salary=10000 :")
m=[Link]()
for r in m:
print(r)
[Link]("select * from employee where name like 's%'")
print()
print("Employee name starting with 's':")
m=[Link]()
for r in m:
print(r)
[Link]("update employee set salary=salary+5000 where salary>=15000")
[Link]()
[Link]("select * from employee ")
print()
print("Table contain after updation in salary : ")
m=[Link]()
for r in m:
print(r)
[Link]("select * from employee limit 3")
print()
print("First 3 rows of table: ")
m=[Link]()
for r in m:
print(r)
[Link]("select * from employee order by name")
print()
print("Table contain in ascending order by name: ")
m=[Link]()
for r in m:
print(r)
[Link]("select * from employee order by age desc")
print()
print("Table contain in descending order by age: ")
m=[Link]()
for r in m:
print(r)
[Link]("delete from employee where age=22")
print()
[Link]("select * from employee ")
print("Table contain after delete operation: ")
m=[Link]()
for r in m:
print(r)
[Link]("drop table employee")
[Link]()
[Link]()
[Link]()
[Link]("drop database company ")
[Link]()
[Link]("show databases")
print()
print("Database: ")
for r in cursor1:
print(r)
[Link]()
[Link]()
Output:
Conclusion: Hence we have successfully executed the given problem statement.
Lab outcome: Explain how to design GUI Applications in Python and evaluate
different database operations.
********************************************************************