全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 python论坛
3822 1
2018-11-07
悬赏 5 个论坛币 未解决
求助:最近在学习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语法错误在哪里

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

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2018-11-7 12:33:44
问题补充:第一个问题已经解决,原因未知,稍晚一点打开数据库后发现表格出现了
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群