From ba3103ea6a69d3633d7801f8999e156e82763764 Mon Sep 17 00:00:00 2001 From: Sunny-Moom Date: Tue, 15 Apr 2025 09:27:46 +0800 Subject: [PATCH] 25.4.15 --- 案例3.py | 2 ++ 案例5.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/案例3.py b/案例3.py index 2ee65eb..d5d3b5d 100644 --- a/案例3.py +++ b/案例3.py @@ -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() diff --git a/案例5.py b/案例5.py index 83b4c1e..c2ebc7f 100644 --- a/案例5.py +++ b/案例5.py @@ -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()