我运行以下代码,在研究了网络之后,我偶然发现了一种使用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)')
答案 0 :(得分:2)
你不 从不连接.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"))