0

I connect Mysql DB to python project , But does not working....How to solve this error?(i learned this code from w3schools)

My Code :

import mysql.connector

Con = mysql.connector.connect(host='localhost', user='root', passwd='', database='python_test')
Cu = Con.cursor()
sql = "INSERT INTO clerk VALUES (%s, %d)"
val = [
 ('Peter', 100),
 ('Amy', 300),
 ('Hannah', 250),
 ('Michael', 1500),
 ('Sandy', 2500),
]

Cu.executemany(sql, val)

Con.commit()

Error :

Traceback (most recent call last):
  File "C:/Users/Ramin/PycharmProjects/First program/Mysql.py", line 23, in <module>
    Cu.executemany(sql, val)
  File "C:\Users\Ramin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mysql\connector\cursor.py", line 652, in executemany
    stmt = self._batch_insert(operation, seq_params)
  File "C:\Users\Ramin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mysql\connector\cursor.py", line 597, in _batch_insert
    "Not all parameters were used in the SQL statement")
mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement
ramin kazemi
  • 43
  • 1
  • 2
  • 10
  • 1
    From the [docs](https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-execute.html): *Specify variables using `%s` or `%(name)s` parameter style (that is, using format or pyformat style).* `%d` is not a valid placeholder for MySQL Connector, hence the numerical values from your parameter tuples do not get used because there's no placeholder to substitute them into. – shmee Aug 01 '19 at 12:33
  • 3
    Possible duplicate of [Not all parameters were used in the SQL statement (Python, MySQL)](https://stackoverflow.com/questions/20818155/not-all-parameters-were-used-in-the-sql-statement-python-mysql) – shmee Aug 01 '19 at 12:34
  • Thank you....changing to %s Solved this problem – ramin kazemi Aug 01 '19 at 12:46

0 Answers0