0% found this document useful (0 votes)
12 views2 pages

MySQL-Python Employee Operations

The document provides a Python program that connects to a MySQL database to perform operations on an 'Employee' table. It includes code for creating the table and inserting a record into it. The program handles database connections, SQL execution, and error management for the insertion process.

Uploaded by

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

MySQL-Python Employee Operations

The document provides a Python program that connects to a MySQL database to perform operations on an 'Employee' table. It includes code for creating the table and inserting a record into it. The program handles database connections, SQL execution, and error management for the insertion process.

Uploaded by

hardeepmahi8
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Program: WAP to Perform all the operations with reference to table ‘Employee’ through

MySQL-Python connectivity.

import [Link]
# Using connect method to connect database
db1 = [Link](host="localhost",user="root",passwd="mysql1234@2022"
,database="testdb");
# using cursor() method for preparing cursor
cursor = [Link]()
# Preparing SQL statement to create EMP table
sql = "CREATE TABLE EMP(empno integer primary key,ename varchar(25) not null,salary
float);"
[Link](sql)
# disconnect from server
[Link]()
# Inserting a record in ‘emp’

import [Link]
db1 = [Link](host="localhost",user="root",passwd="mysql1234@2022"
,database="testdb");
cursor = [Link]()
# Prepareing SQL statement to insert one record with the given values
sql = "INSERT INTO EMP VALUES (6,'NIKITA',98000);"
try:
[Link](sql)
[Link]()
except:
[Link]()
[Link]()

You might also like