変数testをテーブル名として使用して、データベースにデータを挿入しようとしています。しかし、残念ながら私はこれを達成することはできません。誰か助けてくれますか?私の昇給から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