search
HomeTopicsAccessHow python operates access database

How python operates access database

Dec 11, 2020 pm 05:23 PM
accesspythondatabase

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()

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!

Statement
This article is reproduced at:csdn. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool