Skip to content
Snippets Groups Projects
Commit 888c9b6f authored by Bui2.Huan@live.uwe.ac.uk's avatar Bui2.Huan@live.uwe.ac.uk
Browse files

Upload New File

parent 390dcd14
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` python
import sqlite3
try:
# Connect to (or create) myDB.db
conn = sqlite3.connect('myDB.db')
print("Database created and connected successfully!")
# Commit changes and close
conn.commit()
conn.close()
except sqlite3.Error as e:
print(f"An error occurred: {e}")
```
%% Output
Database created and connected successfully!
%% Cell type:code id: tags:
``` python
import sqlite3
conn = sqlite3.connect('myDB.db')
cursor = conn.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS staff (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
position TEXT,
office TEXT,
email TEXT
)''')
cursor.execute("INSERT INTO staff (name, position, office, email) VALUES (?, ?, ?,?)",
('Bob', 'Developer', 'pka','bob@gmail.com'))
conn.commit()
for row in cursor.execute('SELECT * FROM staff'):
print(row)
conn.close()
```
%% Output
(1, 'Bob', 'pka', 'Developer', 'bob@gmail.com')
(2, 'Bob', 'pka', 'Developer', 'bob@gmail.com')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment