我想在我的程序中使用executemany来同时存储20条记录,下面是文档中的内容......
c.executemany(
"""INSERT INTO breakfast (name, spam, eggs, sausage, price)
VALUES (%s, %s, %s, %s, %s)""",
[
("Spam and Sausage Lover's Plate", 5, 1, 8, 7.95 ),
("Not So Much Spam Plate", 3, 2, 0, 3.95 ),
("Don't Wany ANY SPAM! Plate", 0, 4, 3, 5.95 )
] )
Run Code Online (Sandbox Code Playgroud)
但是,我在列表中有我的值,而不是使用我列表中的索引来执行上面的18个版本.
这是我下面的代码......
db = connect_to_db()
cursor = db.cursor()
sql = "INSERT INTO gkey (keyword, date, time, position) VALUES (%s, %s, %s, %s)"
params = [(str(keywords[0]), date, time, position[0])]
cursor.executemany(sql, params)
db.commit() …Run Code Online (Sandbox Code Playgroud)