我试图将一些数据插入数据库使用变量测试作为表名称。但不幸的是,我似乎无法做到这一点。谁能帮我吗?Python插入到%s MySQL
从我养我越来越:
TypeError: unsupported operand type(s) for %: 'tuple' and 'tuple'
我的代码:
test = "hello"
# Open database connection
db = MySQLdb.connect("127.0.0.1","admin","password","table")
# prepare a cursor object using cursor() method
cursor = db.cursor()
# Prepare SQL query to INSERT a record into the database.
sql = ("""INSERT INTO %s (name,
age, gender)
VALUES (%s, %s, %s)""",(test))
try:
# Execute the SQL command
cursor.execute(sql, (name, age, gender))
db.commit()
except:
raise
db.rollback()
# disconnect from server
db.close()
你会得到什么错误?给我们一个线索...... – Stuart
@Stuart添加了更多信息! – user3702643