pymysql insert ProgrammingError1064

用pymysql向數據庫插入比較長的文本,一直出錯:
Error:ProgrammingError: (1064, "You have an error in your SQL syntax;…

sql = "INSERT INTO train_dataset(news,label) VALUES ("+"\""+new+"\""+")"
sql =  "INSERT INTO train_dataset(news,label) VALUES ('%s)"%new
 sql = "INSERT INTO train_dataset(news,label) VALUES ('%s)"
 cursor.execute(sql,(line))

都報這個錯誤
後來發現,是sql裏這個’%s’不能加引號……

cursor = db.cursor()  # 獲取遊標

sql = "INSERT INTO test_dataset(news) VALUES (%s)"
cursor.execute(sql,(line))
db.commit()

這個佔位符一直不用’'的啊!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章