Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
22 views

NAME - ANIKET.K - I2 - 39 : Experiment No.11 B

This program demonstrates various database operations using MySQL including: 1) Connecting to a MySQL database and creating a new database called "college1". 2) Creating a table called "student" with two columns within the "college1" database. 3) Inserting records into the "student" table. 4) Updating a record in the "student" table. 5) Deleting a record from the "student" table. 6) Dropping the "college1" database.

Uploaded by

aniket kasturi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

NAME - ANIKET.K - I2 - 39 : Experiment No.11 B

This program demonstrates various database operations using MySQL including: 1) Connecting to a MySQL database and creating a new database called "college1". 2) Creating a table called "student" with two columns within the "college1" database. 3) Inserting records into the "student" table. 4) Updating a record in the "student" table. 5) Deleting a record from the "student" table. 6) Dropping the "college1" database.

Uploaded by

aniket kasturi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

*********************NAME -ANIKET.

K -I2 -39****************
Experiment No.11 b

Aim: Write python programs to understand database operations using Mysql database
creation.

Program Code:
import mysql.connector
mydb =mysql.connector.connect(host="localhost", user="saloni",
passwd="password123")

print(mydb)

if(mydb):
print("connection successful")
else:
print("connection unsuccessful ")

mycursor =mydb.cursor()
mycursor.execute("Create database college1")
mycursor.execute("Show databases")
print("Database:")
for db in mycursor:
print(db)

mydb1 = mysql.connector.connect(host="localhost", user="saloni",


passwd="password123", database="college1")
mycursor1 =mydb1.cursor()

mycursor1.execute("Create table student (Roll_No int(20) ,Name varchar(100))")


print()
print("Table: ")
mycursor1.execute("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")]
mycursor1.executemany(sqlform,s)

mydb1.commit()

mycursor1.execute("Select * from student")


print("Table content: ")
myresult=mycursor1.fetchall()
for r in myresult:
print(r)

sql="Update student Set Name='Amit' where Roll_No=2"


mycursor1.execute(sql)

mydb1.commit()

mycursor1.execute("Select * from student")


print("Table content after updation : ")
myresult=mycursor1.fetchall()
for r in myresult:
print(r)

sql1 =" Delete from student where Roll_No=3 "


mycursor1.execute(sql1)

mydb1.commit()

mycursor1.execute("Select * from student")


print("Table content after deletion : ")
myresult=mycursor1.fetchall()
for r in myresult:
print(r)

mycursor1.close()
mydb1.close()

mycursor.execute("Drop database college")

mycursor.execute("show databases")
print()
print("Database: ")
for r in mycursor:
print(r)

mycursor.close()
mydb.close()

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.

You might also like