a code
import pymysql # Open database connection db = pymysql.connect("localhost","root","root","db_test01" ) # Use the cursor() method to get the operation cursor cursor = db.cursor() # SQL update statement sql = "UPDATE EMPLOYEE SET AGE = AGE + 1 WHERE SEX = '%c'" % ('M') try: # Execute the SQL statement cursor.execute(sql) # Submit to the database for execution db.commit() print("update OK") except: # rollback on error db.rollback() # close the database connection db.close()
Second run results
update OK