0

Currently, I want to add a list into an Access Database. However, I'm not sure how to. This is my current code:

import pyodbc

conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Users\eesam\OneDrive\Documents\Eesa\Home\Coding\Hacking\Brute Force Attacks\Database.accdb;')
cursor = conn.cursor()

passes = ["1", "69", "hello", "saw", "hiaf", "oln", "oi"]

for i in passes:
    print(i)
    cursor.execute("INSERT INTO PASS (PASSWORD)" +
                    f"VALUES({i})")

    conn.commit()

Each Time I try, I get the error "pyodbc.Error: ('07002', '[07002] [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1. (-3010) (SQLExecDirectW)')"

Could anyone help me please?

4
  • 1
    You missed a space before VALUES and you should put {i} in quotes. Commented Dec 8, 2020 at 11:30
  • 3
    you can use cursor.execute("INSERT INTO PASS (PASSWORD) VALUES (?)", (i,)). This will prevent you of having to add quotes around the i variable. Commented Dec 8, 2020 at 11:41
  • 1
    Also, PASSWORD is a reserved word in Access SQL so you'll need to enclose the column name in square brackets: INSERT INTO PASS ([PASSWORD]) VALUES (?) Commented Dec 8, 2020 at 16:04
  • 1
    related: stackoverflow.com/q/19557920/2144390 Commented Dec 8, 2020 at 16:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.