「Python」SQLiteに接続してレコードを挿入(insert)するサンプル
書式
sqlite3.connect(r’dbのパス’)
使用例
# coding: utf-8
import sqlite3
conn = sqlite3.connect(r'D:\study\sqltest.db')
c = conn.cursor()
try:
c.execute("INSERT INTO user VALUES (?,?,?)",(100,'u02','u03'))
c.execute("INSERT INTO user VALUES (:uid,:uname,:r1)",(200,'u004','u7'))
except sqlite3.Error as e:
print(e)
conn.commit()
conn.close()
# coding: utf-8
import sqlite3
conn = sqlite3.connect(r'D:\study\sqltest.db')
c = conn.cursor()
try:
c.execute("INSERT INTO user VALUES (?,?,?)",(100,'u02','u03'))
c.execute("INSERT INTO user VALUES (:uid,:uname,:r1)",(200,'u004','u7'))
except sqlite3.Error as e:
print(e)
conn.commit()
conn.close()
# coding: utf-8 import sqlite3 conn = sqlite3.connect(r'D:\study\sqltest.db') c = conn.cursor() try: c.execute("INSERT INTO user VALUES (?,?,?)",(100,'u02','u03')) c.execute("INSERT INTO user VALUES (:uid,:uname,:r1)",(200,'u004','u7')) except sqlite3.Error as e: print(e) conn.commit() conn.close()