python操作sqlite数据库
程序员文章站
2022-03-13 08:37:17
...
一 代码
E:\python\python可以这样学\第14章数据库编程\code>python
Python3.6.1(v3.6.1:69c0db5,Mar212017,18:41:36)[MSC v.190064 bit (AMD64)] on win32
Type"help","copyright","credits"or"license"for more information.
>>>import sqlite3
>>> conn=sqlite3.connect('example.db')
>>> c=conn.cursor()
>>> c.execute('''CREATE TABLE COMPANY
... (ID INT PRIMARY KEY NOT NULL,
... NAME TEXT NOT NULL,
... AGE INT NOT NULL,
... ADDRESS CHAR(50),
... SALARY REAL)''')
<sqlite3.Cursor object at 0x0000024CB70C3AB0>
>>> c.execute("INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) \
... VALUES (1, 'Paul', 32, 'California', 20000.00 )")
<sqlite3.Cursor object at 0x0000024CB70C3AB0>
>>> conn.commit()
>>> conn.close()
二 运行结果