The most common way for python to operate the access database is to use the pyodbc library.
See the following code for details:
# -*- coding: utf-8 -*- # 功能:python连接access2010数据库(.accdb) import pyodbc DBfile = r"h:\xiaonei\xnzy.accdb" # 数据库文件 conn = pyodbc.connect(r"Driver={Microsoft access Driver (*.mdb, *.accdb)};DBQ=" + DBfile + ";Uid=;Pwd=;charset='utf-8';") #用charset设置字符集 cursor = conn.cursor() SQL = '''insert into table1 (title,type,) values ('通知','通知公告')''' #注意:在SQL语句中必须用单引号',使用双引号"pyodbc会提示错误,整个语句可以用三引号。 cursor.execute(SQL) conn.commit() cursor.close() conn.close()
Related recommendations: access database tutorial
The above is the detailed content of How python operates access database. For more information, please follow other related articles on the PHP Chinese website!