0

我运行以下代码,在研究了网络之后,我偶然发现了一种使用 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)')
4

1 回答 1

2

永远不会 在. 请参阅db api 常见问题解答.execute()

用这个:

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"))
于 2012-09-13T19:56:47.977 回答