gpt4 book ai didi

python - 属性错误 : 'MySQLCursor' object has no attribute 'commit'

转载 作者:可可西里 更新时间:2023-11-01 06:54:17 24 4
gpt4 key购买 nike

def fillblast(sequentie, titel_lijst, score_lijst, e_lijst, iden_lijst, pos_lijst, gaps_lijst): 
conn = mysql.connector.connect(host = "ithurtswhenip.nl", user = "pg2", password = "pg2", database= "pg2", port= "3307")
cursor = conn.cursor()
Blast = 1000
for i in range(0,len(titel_lijst)):
Blast =+ 2
cursor.execute("INSERT INTO `pg2`.`Blast` (`Blast_id`, `Blast_seq`, `Blast_titel`, `Blast_score`, `Blast_E`, `Blast_gaps`, `Blast_pos`, `Blast_iden`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s);", (Blast, sequentie[i] ,titel_lijst[i], score_lijst[i], e_lijst[i], iden_lijst[i], pos_lijst[i], gaps_lijst[i]))
print("1 record toegevoegd")
cursor.commit()
cursor.close()
conn.close()

我收到以下错误:

AttributeError: 'MySQLCursor' object has no attribute 'commit'

它是怎么来的,哪里出了问题?我尝试连接 MySQLWorkbench。

编辑:

现在我得到以下错误:

mysql.connector.errors.DatabaseError: 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

最佳答案

因为你不能提交游标!您必须提交连接。

# cursor.commit() --> This is wrong!
conn.commit() # This is right

Check the docs ...

关于python - 属性错误 : 'MySQLCursor' object has no attribute 'commit' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30842031/

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