Database Connectivity Programs
Database Connectivity Programs
Database Connectivity Programs
Source Code
1. ADD RECORD
2. DISPLAY RECORD
0. EXIT
Enter Choice :1
Enter Employee Number :101
Enter Name :n1
Enter Department :d1
Enter Salary :10000
## Data Saved ##
1. ADD RECORD
2. DISPLAY RECORD
0. EXIT
Enter Choice :1
Enter Employee Number :102
Enter Name :n2
Enter Department :d3
Enter Salary :20000
## Data Saved ##
1. ADD RECORD
2. DISPLAY RECORD
0. EXIT
Enter Choice :2
EMPNO NAME DEPARTMENT SALARY
101 n1 d1 10000
102 n2 d3 20000
1. ADD RECORD
2. DISPLAY RECORD
0. EXIT
Enter Choice :
=====================================================================================
1. cur.fetchall()- [(1,"raj","cardio"),(2,"sam","dermatologist"),(3,"bob","ophalmologist")]
It returns a list of tuples
If there are no records to fetch, then fetchall() returns empty list
2. cur.fetchone()- (1,"raj","cardio")
It returns a tuple
If there are no records to fetch, then fetchone() returns None
3. cur.fetchmany(2)- [(1,"raj","cardio"),(2,"sam","dermatologist")]
It returns a list of tuples
If there are no records to fetch, then fetchmany(n) returns empty list
new style:
str="select * from student where marks>{} and section='{}'".format(70,'A')
str="select name,age from student where age<{} and marks between {} and {}".format(30,40,70)
old style:
str="select * from student where marks>%s"%(70,)" and section=%s"%('A',)
2) Program to connect with database and store record of employee and display records.
Source Code
Output
########################################
EMPLOYEE SEARCHING FORM
########################################
3) Program to connect with database and update the employee record of entered empno.
Source Code
Output
########################################
EMPLOYEE UPDATION FORM
########################################
Source Code
Output
########################################
EMPLOYEE DELETION FORM
########################################
Ans:
import mysql.connector as mycon
con=mycon.connect(host="localhost",user="root",password="abc",database="iit")
try:
cur=con.cursor()
cur.execute("select * from Faculty where salary>70000")
result=cur.fetchall()
print(data)
except:
con.rollback()
con.close()