gpt4 book ai didi

python - 插入表 MySQL 和 Python

转载 作者:行者123 更新时间:2023-11-29 08:46:36 24 4
gpt4 key购买 nike

我运行了以下代码,在研究了网络之后,我偶然发现了一种使用 Python 将记录插入 MySQL 的方法。我执行了以下代码

i = 0

for j in range(starting_index,ending_index):
for i in range(0,len(s)):
c.append(nnp_array_index_coloumn.count(i))
add1 = add1 + c[i-1]
add2 = add1 + c[i]
var_string_1 = ', '.join('?' * len(nnp_array[add1:add2]))
cursor.execute("INSERT INTO tblauto_tagged ( propernoun_SRNO,tagger,train ,propernoun,propernoun_ID)VALUES (%d, %s,%s, %s, %s)" % (j, str(iput),str(corpora), var_string_1,"AUX" ))
for item in nnp_array_index_coloumn:
if item not in uniques:
uniques.append(item)
add1=0;add2=0

生成以下错误

Traceback (most recent call last):
File "C:/Users/vchauhan/Desktop/test_for_write.py", line 111, in <module>
cursor.execute("INSERT INTO tblauto_tagged ( propernoun_SRNO,tagger,train ,propernoun,propernoun_ID)VALUES (%d, %s,%s, %s, %s)" % (j, str(iput),str(corpora), var_string_1,"AUX" ))
Error: ('07001', '[07001] [MySQL][ODBC 5.1 Driver][mysqld-5.1.61-community]SQLBindParameter not used for all parameters (506) (SQLExecDirectW)')

最佳答案

从不.execute()中连接字符串。请参阅db api faq

使用这个:

q = """
INSERT INTO
tblauto_tagged
(
propernoun_SRNO,
tagger,
train,
propernoun,
propernoun_ID
) VALUES (
%d,
%s,
%s,
%s,
%s
)
"""
cursor.execute(q,(j,str(iput),str(corpora),var_string_1,"AUX"))

关于python - 插入表 MySQL 和 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12413761/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com