0% found this document useful (0 votes)
11 views3 pages

SQL Connector

Tyeyuwiwnwnwjwjwbhhughnjjjj.

Uploaded by

parth Patel
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)
11 views3 pages

SQL Connector

Tyeyuwiwnwnwjwjwbhhughnjjjj.

Uploaded by

parth Patel
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

23)To write a Python Program to integrate MYSQL

with Python by inserting records to Emptable and


display the records.
import mysql.connector
con=mysql.connector.connect (host='localhost', username='root' ,password='root',database='STU')
if con.is_connected():
cur=con.cursor()
opt='y'
while opt=='y':
No-int (input("Enter Roll Number: "))
Name=input ("Enter Name: ")
Age-input ("Enter Age:")
Fees=int (input ("Enter Fees: "))
Query="INSERT INTO EMP VALUES ({},'{}','{}',{})".format (No, Name, Age,Fees)
cur.execute (Query)
con.commit()
print ("Record Stored Successfully")
opt-input("Do you want to add another student details (y/n):")
Query="SELECT FROM STU";
cur.execute (Query)
data=cur.fetchall()
for i in data:
print(i)
con.close()

Output:
Enter Roll Number:8
Enter Name:vrund
Enter Age:17
Enter Fees:300
Record Stored Successfully
Do you want to add another student details(y/n):y
Enter Roll Number:9
Enter Name:het
Enter Age:16
Enter Fees:150
Record Stored Successfully
Do you want to add another student details(y/n):n
(8, ‘vrund’ , 17 , 300)
(9, ‘het’ , 16 , 150)
24)To write a Python Program to integrate MYSQL
with Python to search an student using Roll
number and display the record if present in already
existing table STU, if not display the appropriate
message.
import mysql.connector
con=mysql.connector.connect (host='localhost',
username='root' ,password='root',database='STU')
if con.is_connected():
cur=con.cursor()
print ("Welcome to student Search Screen”)
No=int(input("Enter the Roll number to search")
Query="SELECT FROM STU WHERE Roll number={}".format (No)
cur.execute(Query)
data=cur.fetchone()
If data!=None:
else:
print (data)
print("Record not Found!")
con.close()

Output:
Welcome to student Search Screen
Enter the Roll number to search:2
(2, 'sankalp',17 ,250 )

Welcome to student Search Screen


Enter the Roll number to search:404
Record not Found!
import mysql.connector
con=mysql.connector.connect (host='localhost',
username='root' ,password='root',database='STU')
if con.is_connected():
cur=con.cursor()
print (Welcome to student detail update Screen’)
No-int(input("Enter tha Roll number to Update:")) Ouery="SELECT FROM STU WHERE Roll number={}"
format (No)
cur.execute (Query)
data=cur.fetchone()
If data!=None:
else:
print ("Record found datails are: ")
print (data)
ans-input (Do you want to update the fees of the above student (y/n)?:)
If ans=='y' or ans=='Y':
New_Sal=int(input("Enter the new fees of the student:"))
Q1=UPDATE STU SET fees={} WHERE Roll number={}".format (New_Sal, No)
cur.execute(Q1)
con.commit()
print ("student fees Updated Successfully")
Q2="SELECT FROM STU"
cur.execute(Q2)
data=cur.fetchall()
for i In data:
print(i)
print("Record not Found!")

Output:

Welcome to student detail update Screen


Enter the Roll number to search:3
Record found details are:
(3 , 'varun' , 18 , 350)
Do you want to update the fees of the above student (y/n)?:y
Enter the New fees of an student:300
Exployee Salary Updated Successfully
(3 , 'varun' , 18 ,300)

You might also like