Over a million developers have joined DZone.

Python And Sqllite : Simplest Example

DZone's Guide to

Python And Sqllite : Simplest Example

· ·
Free Resource

import sqlite

con = sqlite.connect('mydatabase.db')
cur = con.cursor()
#~ cur.execute('CREATE TABLE foo (o_id INTEGER PRIMARY KEY, fruit VARCHAR(20), veges VARCHAR(30))')
#~ con.commit()
cur.execute('INSERT INTO foo (o_id, fruit, veges) VALUES(NULL, "apple", "broccoli")')
print cur.lastrowid

cur.execute('SELECT * FROM foo')
print cur.fetchall()

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}