Here is my code:
import mysql.connector
import datetime
import dateutil.parser
import soundfile as sf
mydb = mysql.connector.connect(
host="localhost",
user="py",
password="12345678",
database="mydatabase"
)
mycursor = mydb.cursor()
print(res )
val = res
sql = """INSERT INTO customers (adress) VALUES (%s) """
mycursor.executemany(sql, val)
mydb.commit()
print(mycursor.rowcount, "record inserted.")
The values of list is
['2021-05-21 04:00:32.071', '2021-05-21 04:00:33.071', '2021-05-21 04:00:34.071', '2021-05-21 04:00:35.061', '2021-05-21 04:00:36.071', '2021-05-21 04:00:37.071', '2021-05-21 04:00:38.071', '2021-05-21 04:00:39.061', '2021-05-21 04:00:40.071', '2021-05-21 04:00:41.071', '2021-05-21 04:00:42.071', '2021-05-21 04:00:43.061', '2021-05-21 04:00:44.071', '2021-05-21 04:00:45.071']
and here is the error:
ProgrammingError: Not all parameters were used in the SQL statement
full list is not set asd column so that we use for loop herwe is code:
import mysql.connector
import datetime
import dateutil.parser
import soundfile as sf
mydb = mysql.connector.connect(
host="localhost",
user="py",
password="12345678",
database="mydatabase"
)
mycursor = mydb.cursor()
for i in range(len(res)):
val = res[i]
sql = "INSERT INTO timestamps ({}) VALUES ('{}') ".format(colname,val)
mycursor.execute(sql, val)
mydb.commit()
print(mycursor.rowcount, "record inserted.")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.