我在Mac上运行Python3,以测试简单的sql数据库。我有以下代码
import sqlite3
# connecting to the database
connection = sqlite3.connect("myTable.db")
crsr = connection.cursor()
# SQL command to create a table in the database
sql_command = """CREATE TABLE emp (
staff_number INTEGER PRIMARY KEY,
fname VARCHAR(20),
lname VARCHAR(30),
gender CHAR(1),
joining DATE);"""
# execute the statement
crsr.execute(sql_command)
# SQL command to insert the data in the table
sql_command = """INSERT INTO emp VALUES (23, "Rishabh", "Bansal", "M", "2014-03-28");"""
crsr.execute(sql_command)
crsr.execute(sql_command)
connection.commit()
connection.close()
运行此代码时,出现错误:
Traceback (most recent call last):
File "test.py", line 8, in <module>
connection = sqlite3.connect("myTable.db")
sqlite3.OperationalError: unable to open database file
我想念什么?我试图取代("myTable.db")
以(".myTable.db")
和("./myTable.db")
,但同样的问题。请提出建议。
更改对SQLite数据库文件的权限。
sudo chmod 775 /FolderOfSQLiteDBfile/
sudo chmod 664 /FolderOfSQLiteDBfile/sqlite.db
chmod 775 /FolderOfSQLiteDBfile/
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句