This commit is contained in:
晴月 2025-04-15 09:27:46 +08:00
parent cb2009958f
commit ba3103ea6a
2 changed files with 6 additions and 0 deletions

View File

@ -9,6 +9,8 @@ cursor=db.cursor()
sql="INSERT INTO EMPLOYEE(FIRST_NAME, LAST_NAME, AGE, SEX, INCOME) VALUE ('Mac','Mohan',20,'M',2000)"
try:
cursor.execute(sql)
cursor.execute('SELECT * FROM EMPLOYEE')
print(cursor.fetchall())
db.commit()
except:
db.rollback()

View File

@ -8,7 +8,11 @@ db=pymysql.connect (
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()