Python MYSQL update statement

前端 未结 5 1624
时光取名叫无心
时光取名叫无心 2020-11-27 02:27

I\'m trying to get this Python MYSQL update statement correct(With Variables):

cursor.execute (\"UPDATE tblTableName SET Year=%s\" % Year \", Month=%s\" % Mo         


        
5条回答
  •  盖世英雄少女心
    2020-11-27 03:24

    Neither of them worked for me for some reason.

    I figured it out that for some reason python doesn't read %s. So use (?) instead of %S in you SQL Code.

    And finally this worked for me.

       cursor.execute ("update tablename set columnName = (?) where ID = (?) ",("test4","4"))
       connect.commit()
    

提交回复
热议问题