python - SQL 查询的值部分中的占位符错误
问题描述
您好我正在尝试使用 python 从 excel 将数据导入访问数据库。
下面是我尝试过的代码
import xlrd
import pyodbc
# opening the excel sheets
incoming=xlrd.open_workbook(r'C:\Users\Desktop\Incoming.xlsx')
sheet_incoming=incoming.sheet_by_name('Incoming')
print(sheet_incoming)
# connecting to access database
conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Users\Desktop\E CX DB.accdb;')
dbcurs=conn.cursor()
incoming_query = """INSERT INTO Incoming (SR_NO,SUP,ID,TYPE,SETUP_DATE,BU,Month_,Year_,RAF_IND)VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s)"""
for r in range(1,sheet_incoming.nrows):
SR_NO = sheet_incoming.cell(r,0).value
SUP = sheet_incoming.cell(r,1).value
ID = sheet_incoming.cell(r,2).value
TYPE = sheet_incoming.cell(r,3).value
SETUP_DATE = sheet_incoming.cell(r,4).value
BU = sheet_incoming.cell(r,5).value
Month_ = sheet_incoming.cell(r,6).value
Year_ = sheet_incoming.cell(r,7).value
RAF_IND = sheet_incoming.cell(r,8).value
#assigning values
values =(SR_NO,SUP,ID,TYPE,SETUP_DATE,BU,Month_,Year_,RAF_IND)
# execute upload
dbcurs.execute(incoming_query,values)
dbcurs.close()
conn.commit()
conn.close()
我得到的错误是Syntax error in query expression '%s'. (-3100) (SQLPrepare)")
问候,任。
解决方案
推荐阅读
- sql-server - 尝试在过程中执行过程时出错
- python - 找出所有小于 200 万的奇数斐波那契数的总和
- java - 为什么我的应用会抛出空指针异常?
- r - DBI SQL Server ODBC 连接中返回的数据库对象缺少字母
- linux - 如何使用 ipcalc 在 Bash 脚本中验证 IP?
- javascript - 如何从地图函数返回数据
- c# - 使用 XMLSerializer 在 WPF 应用程序中读取/保存设置文件
- r - 使用多个类别的 R 数据绘制图时遇到问题
- c - 添加两行并将总和存储在最后一行
- python-3.x - 如何使用 matplotlib plt.imshow 更改热图的 y 刻度标签?