【发布时间】:2013-07-18 21:59:47
【问题描述】:
我正在尝试使用 Python 和 MySQLdb 将一些数据插入 MySQL DB。当我执行以下操作时:
query = "INSERT INTO universitats (universitat) VALUES ('%s')" % (lloc)
cursor.execute(query)
db.commit()
我收到此错误:
Traceback (most recent call last):
File "read.py", line 39, in <module>
cursor.execute(query)
File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Hospitalet de Llobregat')' at line 1")
我做错了什么?
【问题讨论】:
-
能否也提供一些
query=...前面的代码行,可以帮助解释lloc的价值和universitats的设计
标签: python mysql insert mysql-python