Home > Topics > Access > body text

How python operates access database

王林
Release: 2020-12-11 17:23:19
forward
10334 people have browsed it

How python operates access database

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()
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template