【发布时间】:2016-11-13 17:44:31
【问题描述】:
我尝试了所有可能的方法。我在堆栈中包含了字符串的 backQuotes,但没有任何效果。它像往常一样重复错误。 我还尝试了一些在其他 python 文件中工作的查询,但它仍然显示相同。我也尝试使用不带连字符的字符串进行查询,即使它不起作用。我在这里找不到问题所在。
import MySQLdb
import sys
from PyQt4 import QtCore, QtGui, uic
qtCreatorFile = "Studisplay.ui" # Enter file here.
Ui_MainWindow1, QtBaseClass = uic.loadUiType(qtCreatorFile)
class stuDisplay(QtGui.QMainWindow, Ui_MainWindow1,QtGui.QTableWidget):
def __init__(self,ID):
#super(stuDisplay, self).__init__(parent)
QtGui.QMainWindow.__init__(self)
Ui_MainWindow1.__init__(self)
QtGui.QWidget.__init__(self)
self.setupUi(self)
obj = MySQLdb.connect("localhost", "root", "1234567", "python")
#The value of ID here is 14-VEC-244 I also tried `14-VEC-244` but did not work
sql = 'SELECT MEMname FROM Borrowed WHERE MemberID ='+ str(ID)
cursor = obj.cursor()
cursor.execute(sql)
name=cursor.fetchone()
print name
我收到此错误:
Traceback(最近一次调用最后一次):文件 “/home/gautham/PycharmProjects/LIBALERT/Login.py”,第 105 行,在 pushButton_clicked self.call = StuSecond.stuDisplay(StuID) 文件“/home/gautham/PycharmProjects/LIBALERT/StuSecond.py”,第 22 行,在 初始化 cursor.execute(sql) 文件“/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py”,第 226 行,在 执行 self.errorhandler(self, exc, value) 文件“/usr/lib/python2.7/dist-packages/MySQLdb/connections.py”,第 36 行,在 默认错误处理程序 提高错误值 _mysql_exceptions.OperationalError: (1054, "'where 子句'中的未知列 'VEC'")
【问题讨论】: