import pymysql
no =int(input('部门编号:'))
name =input('部门名称:')
location =input('所在地:')# 1.创建连接对象
conn = pymysql.connect(host='10.7.190.82', port=3306,
user='wangdachui', password='123123',
database='hrs', charset='utf8mb4')try:with conn.cursor()as cursor:
affected_rows = cursor.execute('insert into tb_dept values (%s,%s,%s)',(no, name, location))if affected_rows ==1:print('添加部门成功')
conn.commit()except pymysql.MySQLError as err:
conn.rollback()print('错误提示:', err)finally:
conn.close()
**'delete from tb_dept where dno = %s',
(no, )**
**'insert into tb_dept values (%s,%s,%s)',
(no, name, location)**
**'uodate tb_dept set dloc=%s where dno=%s',
(location,no)**