【发布时间】:2014-04-24 16:31:39
【问题描述】:
我一直在尝试使用 python 中的以下代码将数据插入数据库:
import sqlite3 as db
conn = db.connect('insertlinks.db')
cursor = conn.cursor()
db.autocommit(True)
a="asd"
b="adasd"
cursor.execute("Insert into links (link,id) values (?,?)",(a,b))
conn.close()
代码运行没有任何错误。但是不会更新数据库。我尝试添加conn.commit(),但它给出了一个错误,提示找不到模块。请帮忙?
【问题讨论】:
-
我不确定:是否可能需要在获取光标之前设置自动提交?
-
也试过了。得到相同的错误“模块”对象没有属性“自动提交”
-
AttributeError: 'module' object has no attribute 'autocommit'。sqlite3模块上没有这样的方法,设置 autocommit 会完全不同。 -
@MartijnPieters 不能使用自动提交怎么办?