简体   繁体   中英

Python - SQL: How do I insert these variables into a table in a database?

the program must store these details in a table. I'm new to SQL and would like to know how to insert variables

    c.execute('''INSERT INTO userAcc(name, dob, age) VALUES(%s,%s,%s)'''(name1, dob1, age1))
    conn.commit()
    c.close()
    conn.close()

SQLite does not support the %s syntax as a placeholder ( https://docs.python.org/3/library/sqlite3.html ). Use question marks instead, and don't forget to insert a comma after the SQL string:

c.execute('''INSERT INTO userAcc(name, genre, artist) VALUES(?,?,?)''', (name1, genre1, artist1))

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM