尝试在Access DB中查询日期,并不断返回以下错误:
Traceback (most recent call last):
File "C:/Users/sniederriter/Desktop/SATG.py", line 10, in <module>
for row in cursor.execute(SQL):
File "C:\Python34\lib\site-packages\pypyodbc-1.3.3-py3.4.egg\pypyodbc.py", line 1605, in execute
self.execdirect(query_string)
File "C:\Python34\lib\site-packages\pypyodbc-1.3.3-py3.4.egg\pypyodbc.py", line 1631, in execdirect
check_success(self, ret)
File "C:\Python34\lib\site-packages\pypyodbc-1.3.3-py3.4.egg\pypyodbc.py", line 986, in check_success
ctrl_err(SQL_HANDLE_STMT, ODBC_obj.stmt_h, ret, ODBC_obj.ansi)
File "C:\Python34\lib\site-packages\pypyodbc-1.3.3-py3.4.egg\pypyodbc.py", line 954, in ctrl_err
raise ProgrammingError(state,err_text)
pypyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'Date *'.")
这是我的代码:
import pypyodbc
DBfile = (r'C:\Users\sniederriter\Desktop\SATGexpenses.accdb')
conn = pypyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ='+DBfile)
cursor = conn.cursor()
print(DBfile)
SQL = 'SELECT Date * FROM 20142015;'
for row in cursor.execute(SQL):
print (row.Date)
cursor.close()
conn.close()
答案 0 :(得分:0)
您的MySQL查询错误。以下代码选择表中的所有字段:
SELECT * FROM Table
如果您想要特定字段写:
SELECT field1, field2, field3 FROM table
但只做其中一件事。全部或指定的字段。