求助:最近在学习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语法错误在哪里
请高手帮忙指点迷津。特别感谢。