getting an error when trying to import a list into a mysql table

2024/10/7 12:25:56

whenever i try to add a list into the mysql table I get an error : 'ProgrammingError: Not all parameters were used in the SQL statement'

ive tried to look online but all i could found is that i need to use %s to solve this and not any other type of placeholders but i alredy do..

my code (just mentioning that i have like 20 name in that list, but i dont think it really matters):

mydb=mysql.connector.connect(host='localhost',user=d,passwd=z,database=y)
listname=['name1','name2','name3','name4']
mycursor=mydb.cursor()
mysqlcommand='INSERT INTO tabletest (firstname) values (%s)'
mycursor.executemany(mysqlcommand,listname)

thank you!

Answer

The second argument to executemany must be a sequence of sequences or mappings, i.e.

listname=[('name1',), ('name2',), ('name3',), ('name4',)]

See https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-executemany.html:

This method prepares a database operation (query or command) and executes it against all parameter sequences or mappings found in the sequence seq_of_params.

https://en.xdnf.cn/q/118828.html

Related Q&A

Getting a view does not return a valid response error message on my flask chatbot [duplicate]

This question already has answers here:Flask view return error "View function did not return a response"(3 answers)Closed 3 years ago.Trying to create a whatsapp bot on Twilio that limits the…

Django how to add data to Object from queryset

I would like show list of clients and show tags assigned to them but I have problem because I have my tags in other table and I dont know how to connect data together. Clients can have couple of tags o…

before_action ... only: how to do this in python flask? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 5 years ago.Improve…

Destroy function not destroying a frame efficiently after the first iteration in Tkinter Python

I have built a code that saves the calculated data at every iteration in a for loop and the results are stored in 3 different csv files. These saved results are read in another python code that display…

Access columns and rows of numpy.ndarray

I currently struggling with extracting certain columns and rows from a matrix stored as a numpy.ndarray. I have a list in which Ive appended these numpy.ndarrays. This list is stored in a variable name…

How to access instance object in list and display there data? in python

class Bank:def __init__(self, name, balance=0):self.name = nameself.balance = balance# def Display_details(self):# print( self.name),# print(self.balance),#### def Withdraw(self, a):# self.…

Using Class, Methods to define variables

I have a number of chemicals with corresponding data held within a database, how do I go about returning a specific chemical, and its data, via its formula, eg o2.class SourceNotDefinedException(Except…

Python Tkinter: Color changing grid of buttons?

I understand that you can make a button that can do some actions when clicked with Tkinter, but how can I just make a button that turns from one color to another when clicked? Then, from that, how do …

Writing a function that checks prime numbers

def primecheck(num): if num > 1: for i in range(2, num): if (num % i) == 0: return False breakelse: return TrueIm trying to make a function that checks if an input is prime or not. This code does …

Getting error code 1 while installing geopandas with pip

This is the error I get when trying to install geopandas using pip install geopandas. Im using Python 3.7.Collecting geopandasUsing cached https://files.pythonhosted.org/packages/24/11/d77c157c16909bd7…