Warm tip: This article is reproduced from serverfault.com, please click

Connect to SQLite3 in PyCharm

发布于 2020-11-28 00:22:59

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?

Questioner
Piers Thomas
Viewed
0
thebjorn 2020-11-28 08:25:56

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