python连接access数据库odbc_求助:python3 中使用pypyodbc.py读写ACCESS数据库遇到问题:...

求助:最近在学习python3 中使用pypyodbc.py读写ACCESS数据库遇到几个问题,请高手不吝赐教:

程序代码如下:

import pypyodbc

stock_info=[('300674', '2018-11-07'), ('600604', '1992-03-27'), ('600462', '2003-09-03')]

try:

conn=pypyodbc.win_connect_mdb('c:\\users\\administrator\\desktop\\t1.mdb')

except Exception  as e :

#print(e)

pypyodbc.win_create_mdb('c:\\users\\administrator\\desktop\\t1.mdb')

conn = pypyodbc.win_connect_mdb('c:\\users\\administrator\\desktop\\t1.mdb')

cur=conn.cursor()

try:

cur.execute("CREATE TABLE code_list(code varchar(6),begaindate varchar(8))")

except Exception as e:

print('get the error info if the table has been not created:',e)

try:

record=cur.execute("SELECT * FROM code_list")

except Exception as e:

print("check that the table has been created:",e)

print("the table has been created")

try:

cur.executemany("INSERT INTO code_list(code,begaindate) VALUES(%s,%s)",stock_info)

except Exception as e:

print('the error when insert into is:',e)

cur.commit()

cur.close()

conn.close()

运行显示如下:

D:\MyPython\venv\Scripts\python.exe D:/MyPython/p02.py

the table has been created

the error when insert into is: ('42000', "[42000] [Microsoft][ODBC Microsoft Access Driver] 语法错误 在查询表达式 '%s' 中。")

Process finished with exit code 0

问题如下:

第一:程序中创建表格code_list然后读取表格均未报错误和异常,但打开数据库后却没有这个表格(刷新或重新打开数据库也没有)

第二:运行显示中提示executemany方法中的SQL语法错误在哪里

请高手帮忙指点迷津。特别感谢。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值