大家好,小弟是 Python 新手,非本科系自学
最近在学习将 Python 的资料汇入 SQLite
我先建一个SQLite的资料表
import sqlite3
conn = sqlite3.connect('sqlite01.db')
print("Opened database successfully")
c = conn.cursor()
c.execute('''CREATE TABLE worknowapp_job
(ID INT PRIMARY KEY NOT NULL,
JOB_NAME CHAR NOT NULL,
JOB_URL CHAR NOT NULL);''')
print("Table created successfully")
conn.commit()
conn.close()
接着我想试将设定好的变量写入 SQLite,程式码如下:
import sqlite3
name ="测试1"
url = "/jobs/10101"
conn = sqlite3.connect('sqlite01.db')
c = conn.cursor()
print ("Opened database successfully")
c.execute("INSERT INTO worknowapp_job (ID,JOB_NAME,JOB_URL) \
VALUES (1,name,url )");
conn.commit()
print("Records created successfully")
conn.close()
但却出现以下的错误讯息: