'Not enough parameters for the SQL statement error
i'm trying to import csv file into SQL table but i received this error "Not enough parameters for the SQL statement" i think that it's something in the SQL query ...
import mysql.connector as msql
import csv
conn = msql.connect(host='localhost', user='root', password='', database='test_database')
my_cursor = conn.cursor()
csv_data = csv.reader(open('lycee.csv'))
header = next(csv_data)
print('Importing the CSV Files')
for row in csv_data:
print(row)
my_cursor.execute("INSERT INTO lycee(date,etudiant,universite,age)
VALUES(%d,%s,%s,%d)", row)
conn.commit()
Solution 1:[1]
Asssuming lycee.csv has 4 columns
When you do
my_cursor.execute("INSERT INTO lycee(date,etudiant,universite,age)
VALUES(%d,%s,%s,%d)", row)
you actually pass 1 array argument, but 4 expected. All you need to do is to unwrap your array
my_cursor.execute("INSERT INTO lycee(date,etudiant,universite,age)
VALUES(%d,%s,%s,%d)", *row)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
