python使用sqlite3模块删除数据报错parameters are of unsupported type

import sqlite3
#链接数据库
con = sqlite3.connect('C:\python_learn\DBA\SQLite3demo\sqlite3demo.db')
#创建游标对象
cur = con.cursor()
#编写sql语句
sql = "delete from t_person where pno = ?"
#执行sql
try:
    cur.execute(sql,(1))
    con.commit()
    print("删除成功")
except Exception as e:
    print(e)
    print("删除失败")
    con.rollback()
finally:
    #关闭连接
    #关闭游标
    cur.close()
    con.close()

删除的数据是元组类型,因此1后面应该有逗号,修改后cur.execute(sql,(1,),可以成功执行;

发布了14 篇原创文章 · 获赞 0 · 访问量 153

猜你喜欢

转载自blog.csdn.net/yimaoyingbi/article/details/104323701