SoftTesting/案例5.py
2025-04-15 09:27:46 +08:00

19 lines
465 B
Python

import pymysql
db=pymysql.connect (
host='172.16.1.166',
user='root',
passwd='114514',
database='TESTDB',
)
cursor=db.cursor()
sql="UPDATE EMPLOYEE SET AGE=AGE+1 WHERE SEX = '%c'" % 'M'
try:
cursor.execute('SELECT * FROM EMPLOYEE')
print(f"更改前:{cursor.fetchall()}")
cursor.execute(sql)
cursor.execute('SELECT * FROM EMPLOYEE')
print(f"更改后:{cursor.fetchall()}")
db.commit()
except:
db.rollback()
db.close()