-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlite.py
More file actions
28 lines (26 loc) · 761 Bytes
/
Copy pathsqlite.py
File metadata and controls
28 lines (26 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import sqlite3
# Function to create SQLite database and table
def create_database_table():
try:
conn = sqlite3.connect('ld_data.db')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS Students (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
roll TEXT,
city TEXT,
age INTEGER,
gender TEXT,
state TEXT
)
''')
conn.commit()
except Exception as e:
print(f"Error creating database and table: {e}")
finally:
if 'cursor' in locals():
cursor.close()
if 'conn' in locals():
conn.close()
create_database_table()