大家好,小弟是 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()
但卻出現以下的錯誤訊息: