Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python sqlite insert

import sqlite3

conn = sqlite3.connect('mysqlite.db')
c = conn.cursor()

#records or rows in a list
records = [(1, 'Glen', 8),
			(2, 'Elliot', 9),
			(3, 'Bob', 7)]

#insert multiple records in a single query
c.executemany('INSERT INTO students VALUES(?,?,?);',records);

print('We have inserted', c.rowcount, 'records to the table.')

#commit the changes to db			
conn.commit()
#close the connection
conn.close()
Comment

insert data in sqlite database in python

import sqlite3
# it will create a databse with name sqlite.db
connection= sqlite3.connect('sqlite.db') 
cursor= connection.cursor()
table_query = '''CREATE TABLE Student
               (Name text, Course text, Age real)'''
               
cursor.execute(table_query)
# you need to commit changes as well
connection.commit()
# you also need to close  the connection
connection.close()   
Comment

PREVIOUS NEXT
Code Example
Python :: python regex search group 
Python :: pandas sort 
Python :: ternary operator python 
Python :: time.perf_counter 
Python :: how to delete a csv file in python 
Python :: how to add delay in python 
Python :: scroll horizontal excel 
Python :: python delete white spaces 
Python :: pandas str is in list 
Python :: get list file endswith python 
Python :: df index start from 1 
Python :: datediff in seconds in pandas 
Python :: ursina python 
Python :: cut part of video ffmpeg 
Python :: python iterate through dictionary 
Python :: pygame caption 
Python :: how to change a header in pandas 
Python :: upgrade python wsl 
Python :: python dict sort by value 
Python :: runge kutta 
Python :: how to pause time in python 
Python :: how to print a specific value in a list python 
Python :: python list empty 
Python :: count occurrences of value in array python 
Python :: system to extract data from csv file in python 
Python :: Dropping NaN in dataframe 
Python :: change plot size matplotlib 
Python :: how to return total elements in database django 
Python :: MovieWriter stderr: ffmpeg: error while loading shared libraries: libopenh264.so.5: cannot open shared object file: No such file or directory 
Python :: adf test python 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =