Piers Thomas
Piers Thomas

Reputation: 327

Connect to SQLite3 in PyCharm

I have a python script written to connect to an SQLite3 database in PyCharm to read the data.

I am unable to read the data from the database, I think I am searching for the database incorrectly.

import sqlite3

conn = sqlite3.connect('jdbc:sqlite:identifier.sqlite')

c = conn.cursor()
c.execute("SELECT * FROM database1")

When I run the code I get the following message:

Traceback (most recent call last):
  File "/Users/piersthomas/PycharmProjects/pythonProject1/main.py", line 9, in <module>
    c.execute("SELECT * FROM database1")
sqlite3.OperationalError: no such table: database1

My database is set up like so:

enter image description here

How do I connect to the DB properly?

Upvotes: 0

Views: 3224

Answers (1)

thebjorn
thebjorn

Reputation: 27321

You must pass a filename to the sqlite3.connect('...') function (https://docs.python.org/3/library/sqlite3.html)

Upvotes: 1

Related Questions