如何解决这个问题: 我在执行下面的代码时遇到了类似EOF等错误--
我的代码是:
import mysql.connector as sql
db_con=sql.connect(host="localhost",user="root",passwd="XXXX",database="mydb")
db_cur=db_con.cursor()
db_cur.execute('"update Orders set Freight=case when ShipCountry='USA' then Freight+(0.15*Freight)"' `" when ShipCountry='Canada' then Freight+(0.15*Freight)"``" when ShipCountry='France' then Freight+(0.10*Freight)"``" when ShipCountry='Germany' then Freight+(0.10*Freight)"``" when ShipCountry='Belgium' then Freight+(0.10*Freight)"``" else Freight+(0.05*Freight) end"`
how to solve?????
您需要提交INSERT和UPDATE查询,并在完成后关闭连接
最好使用上下文管理器
像这样:
您还可以在上下文管理器中定义连接变量
如果你观察到它们,就没有右括号
请关闭
db_cur.execute()
的大括号并按照以下步骤操作提交查询
关闭光标
关闭连接
相关问题 更多 >
编程相关推荐