求助:最近在學習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文法錯誤在哪裡
請高手幫忙指點迷津。特别感謝。