Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中使用mysql.connector时在cursor.execute中获取错误_Python_Mysql Python - Fatal编程技术网

在python中使用mysql.connector时在cursor.execute中获取错误

在python中使用mysql.connector时在cursor.execute中获取错误,python,mysql-python,Python,Mysql Python,如何解决这个问题: 我在执行下面的代码时遇到了类似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' t

如何解决这个问题: 我在执行下面的代码时遇到了类似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?????

请关闭
db\u cur.execute()
的大括号,然后按照以下步骤操作

  • 提交到查询

  • 关闭光标

  • 关闭连接


  • 请关闭
    db\u cur.execute()
    的大括号,然后按照以下步骤操作

  • 提交到查询

  • 关闭光标

  • 关闭连接


  • 您需要提交INSERT和UPDATE查询,并在完成后关闭连接

    最好使用上下文管理器

    像这样:

    import mysql.connector as sql
    db_con=sql.connect(host="localhost",user="root",passwd="Redmilenovo#T",database="datagrokr")
    with db_con.cursor() as cursor:
        cursor.execute("""YOUR QUERY HERE""")
    
    db_con.commit()
    db_con.close()
    

    您还可以在上下文管理器中定义连接变量。

    您需要提交插入和更新查询,并在完成后关闭连接

    最好使用上下文管理器

    像这样:

    import mysql.connector as sql
    db_con=sql.connect(host="localhost",user="root",passwd="Redmilenovo#T",database="datagrokr")
    with db_con.cursor() as cursor:
        cursor.execute("""YOUR QUERY HERE""")
    
    db_con.commit()
    db_con.close()
    
    您还可以在上下文管理器中定义连接变量

    EOF代表文件的结尾。此错误通常意味着行中的某个位置有一个开括号,但没有匹配的右括号

    如果你观察到它们,就没有右括号

    EOF代表文件的结尾。此错误通常意味着行中的某个位置有一个开括号,但没有匹配的右括号


    如果您注意到没有右括号,请将代码样本扩展到错误的第14行。请将代码样本扩展到错误的第14行。