*********************NAME -ANIKET.
K -I2 -39****************
Experiment No.11 b
Aim: Write python programs to understand database operations using Mysql database
creation.
Program Code:
import [Link]
mydb =[Link](host="localhost", user="saloni",
passwd="password123")
print(mydb)
if(mydb):
print("connection successful")
else:
print("connection unsuccessful ")
mycursor =[Link]()
[Link]("Create database college1")
[Link]("Show databases")
print("Database:")
for db in mycursor:
print(db)
mydb1 = [Link](host="localhost", user="saloni",
passwd="password123", database="college1")
mycursor1 =[Link]()
[Link]("Create table student (Roll_No int(20) ,Name varchar(100))")
print()
print("Table: ")
[Link]("show tables")
for db in mycursor1:
print(db)
sqlform = "Insert into student(Roll_No,Name) values(%s,%s)"
s=[(1,"Sachin"),(2,"Anjali"),(3,"Shreya")]
[Link](sqlform,s)
[Link]()
[Link]("Select * from student")
print("Table content: ")
myresult=[Link]()
for r in myresult:
print(r)
sql="Update student Set Name='Amit' where Roll_No=2"
[Link](sql)
[Link]()
[Link]("Select * from student")
print("Table content after updation : ")
myresult=[Link]()
for r in myresult:
print(r)
sql1 =" Delete from student where Roll_No=3 "
[Link](sql1)
[Link]()
[Link]("Select * from student")
print("Table content after deletion : ")
myresult=[Link]()
for r in myresult:
print(r)
[Link]()
[Link]()
[Link]("Drop database college")
[Link]("show databases")
print()
print("Database: ")
for r in mycursor:
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.