import MySQLdb
import random
db = MySQLdb.connect (host = "localhost", user = "python-test", passwd = "python", db = "python-test")
cursor = db.cursor()
var = .3
sql = "INSERT INTO RandomInt
(RAND)
VALUES
(var)" # RandomInt is the name of the table and Rand is the Column Name
cursor.execute(sql)
db.commit()
db.close()
我得到一个错误消息,说Operational Error: (1054, "Unknown column 'var' in 'field list'")
为什么我会得到这个错误,以及如何修复这个错误,尽管我已经定义了var?在
这将解决一个问题:
剩下的是写入的表的名称,0.3不是int
编辑:mysqldb的paramstyle是
%s
不是?
。在如前所述,
var
将作为字符串发送到MySQL。试试看吧:
编辑:
^{pr2}$MySQLdb的paramstyle是
format
;根据DB-API是%s
:相关问题 更多 >
编程相关推荐