使用将数组插入SQL Server数据库时出错cursor.executemanypython

2024-06-30 16:14:26 发布

您现在位置:Python中文网/ 问答频道 /正文

下面是我的Python代码。我已将输出填充到“Finaldata”数组中,并尝试使用cursor.executemany(). 在

但我得到了以下错误:

 Traceback (most recent call last):
    File "C:/Users/Arvinth Kumar/PycharmProjects/untitled/Country table.py", line 74, in <module>
   cursor.executemany(Insert_SQL,Finaldata)
    File "C:\Users\Arvinth kumar\AppData\Local\Programs\Python\Python35\lib\site-packages\pypyodbc.py", line 1692, in executemany
      self.execute(query_string, params, many_mode = True)
    File "C:\Users\Arvinth Kumar\AppData\Local\Programs\Python\Python35\lib\site-packages\pypyodbc.py", line 1617, in execute
 check_success(self, ret)
    File "C:\Users\Arvinth Kumar\AppData\Local\Programs\Python\Python35\lib\site-packages\pypyodbc.py", line 1007, in check_success
    ctrl_err(SQL_HANDLE_STMT, ODBC_obj.stmt_h, ret, ODBC_obj.ansi)
    File "C:\Users\Arvinth Kumar\AppData\Local\Programs\Python\Python35\lib\site-packages\pypyodbc.py", line 975, in ctrl_err
    raise ProgrammingError(state,err_text)
    pypyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '@P1'.")

       Process finished with exit code 1

源代码:

^{pr2}$

最终数据数组值:

 [[Timestamp('2005-01-31 00:00:00'), 'SPAIN', '7.65', '105.61', '800.40', 9223.8999999999996, '3.56', '127.61', 86.709999999999994, 9.5662495675239327, 108.43000000000001, 17.014538973937402, 100.0], 
 [Timestamp('2005-02-28 00:00:00'), 'SPAIN', '7.65', '107.27', '795.63', 9391.0, '3.73', '125.83', 86.939999999999998, 9.5409420289855085, 108.43000000000002, 16.896751739115381, 99.333333333333329], 
 [Timestamp('2005-03-31 00:00:00'), 'SPAIN', '7.99', '105.81', '845.28', 9258.7999999999993, '3.64', '128.34', 87.620000000000005, 9.8876477973065509, 108.43000000000001, 16.779617625250101, 98.666666666666671]]

我检查了其他答案,但无法纠正我的错误。 谁能帮帮我吗。谢谢!在


Tags: inpysqlliblocallinesiteusers