用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()
这个占位符一直不用’'的啊!