我試圖將一些數據插入數據庫使用變量測試作爲表名稱。但不幸的是,我似乎無法做到這一點。誰能幫我嗎?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