【脚本语言系列】关于Python数据库访问DAO, 你需要知道的事

如何使用DAO

# -*- coding:utf-8 -*-
import win32com.client

engine = win32com.client.Dispatch("DAO.DBEngine.36")
db = engine.OpenDatabase(r"addresses.mdb")
rs = db.OpenRecordset("address")
rs = db.OpenRecordset("select * from address")
# insert the data
db.Execute('''
insert into address(name, address, createtime)
values("am","shanghai","1990-01-01")
''')
while not rs.EOF:
    print (rs.Fields("address").Value).encode("utf-8")
    rs.MoveNext()
----------------------------------------------------------------------

com_error                            Traceback (most recent call last)

 in ()
      4 engine = win32com.client.Dispatch("DAO.DBEngine.36")
      5 db = engine.OpenDatabase(r"addresses.mdb")
----> 6 rs = db.OpenRecordset("address")
      7 rs = db.OpenRecordset("select * from address")
      8 # insert the data


c:\python27\lib\site-packages\win32com\client\dynamic.pyc in OpenRecordset(self, Name, Type, Options, LockEdit)


com_error: (-2147352567, '\xb7\xa2\xc9\xfa\xd2\xe2\xcd\xe2\xa1\xa3', (0, u'DAO.Database', u"Microsoft Jet \u6570\u636e\u5e93\u5f15\u64ce\u627e\u4e0d\u5230\u8f93\u5165\u8868\u6216\u67e5\u8be2 'address'\u3002 \u786e\u5b9a\u5b83\u662f\u5426\u5b58\u5728\uff0c\u4ee5\u53ca\u5b83\u7684\u540d\u79f0\u7684\u62fc\u5199\u662f\u5426\u6b63\u786e\u3002", u'jeterr40.chm', 5003078, -2146825210), None)

什么是DAO

DAO(Data Access Object)具有面向对象的接口,提供了Microsoft Jet数据库引擎。
DAO模型是设计关系数据库系统结构的对象类的集合。

你可能感兴趣的:(脚本语言)