无法使用Python将数据插入sqlite3数据库

Pet*_*rne 4 python sqlite

我可以成功使用Python创建数据库并运行execute()方法来创建2个新表并指定列名.但是,我无法将数据插入数据库.这是我尝试用于将数据插入数据库的代码:

#! /usr/bin/env python

import sqlite3

companies = ('GOOG', 'AAPL', 'MSFT')

db = sqlite3.connect('data.db')
c = db.cursor()

for company in companies:
    c.execute('INSERT INTO companies VALUES (?)', (company,))
Run Code Online (Sandbox Code Playgroud)

以下是我用于成功创建数据库的代码:

#! /usr/bin/env python

import sqlite3

db = sqlite3.connect('data.db')

db.execute('CREATE TABLE companies ' \
      '( '\
      'company varchar(255) '\
      ')')

db.execute('CREATE TABLE data ' \
      '( '\
      'timestamp int, '\
      'company int, '\
      'shares_held_by_all_insider int, '\
      'shares_held_by_institutional int, '\
      'float_held_by_institutional int, '\
      'num_institutions int '\
      ')')
Run Code Online (Sandbox Code Playgroud)

bal*_*pha 20

尝试添加

db.commit()
Run Code Online (Sandbox Code Playgroud)

插入后.