-1

I am very new to sqlite3. I am looking for a simple way to search a Microsoft Access file (Called "lahman2016") in sqlite3 in Python. I am trying to search for items in the table called "Parks", but the output says that it is not recognizing it as a table in the access file.

Does anyone have any suggestions?

Thanks.

db = sqlite3.connect("lahman2016.db")

cursor = db.cursor()

cursor.execute('''SELECT parkname
                  FROM Parks
                  WHERE city = Toronto''')

And this is the error that was returned:

sqlite3.OperationalError: no such table: Parks

3 Answers3

0

First make sure if the table name is correct. If it's okay, then try this:

import os.path

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
db_path = os.path.join(BASE_DIR, "lahman2016.db")
db = sqlite3.connect(db_path)

cursor = db.cursor()

cursor.execute('''SELECT *
                  FROM Parks
                 ''')

This question was already answered, source: https://stackoverflow.com/a/28126276/6512488

Abdullah
  • 131
  • 1
  • 10
0

Firstly check for correct spelling on your Database name 'lahman2016' and then on your table name 'Parks'. Once thats been checked, let us know.

python_starter
  • 1,509
  • 1
  • 11
  • 18
-1

db = sqlite3.connect("lahman2016.db")

cursor = db.cursor()

cursor.execute(''' SELECT parkname FROM Parks WHERE city = 'Toronto' ''')

  • What exactly is your code trying to do? You only deleted the newlines in the text from OP's code snippet. – Marko Dec 08 '20 at 15:32
  • Please avoid posting code only answers. Please elaborate on the code and explain what it does and why this will be the solution to the question. Also, please use proper formatting. – Korashen Dec 08 '20 at 16:34