Python簡單操作sqlite3的方法示例
本文實例講述了Python簡單操作sqlite3的方法。分享給大家供大家參考,具體如下:
import sqlite3
def Test1():
#con =sqlite3.connect("D:\\test.db")
con =sqlite3.connect(":memory:") #store in memory
cur =con.cursor()
try:
cur.execute('create table score(id integer primary key,name varchar(10),scores integer)')
cur.execute("insert into score values(0,'Rose',87)")
cur.execute("insert into score values(1,'Alice',78)")
cur.execute("insert into score values(2,'Helon',100)")
cur.execute("insert into score values(3,'Tom',98)")
cur.execute("insert into score values(4,'jack',198)")
cur.execute("insert into score values(5,'Tony',198)")
cur.execute("insert into score values(6,'David',99)")
cur.execute("update score set scores =? where id=?",(45,3))
cur.execute("update score set name=? where id=?",("John",0))
cur.execute("delete from score where id =1")
except Exception,e:
print "There are some except",e
con.commit()
print "Insert Complete"
print "-----------------------------------------"
print "Last row id is ",cur.lastrowid
cur.execute('select * from score')
print cur.fetchall()
print "----------------------------------------"
cur.execute("select count(*) from score")
print "Current Rows is :",cur.fetchall()[0]
cur.close()
con.close()
if __name__ =='__main__':
Test1()
print "hello world"
更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python常見數(shù)據(jù)庫操作技巧匯總》、《Python編碼操作技巧總結(jié)》、《Python圖片操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python Socket編程技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對大家Python程序設(shè)計有所幫助。
相關(guān)文章
Pyinstaller打包.py生成.exe的方法和報錯總結(jié)
今天小編就為大家分享一篇關(guān)于Pyinstaller打包.py生成.exe的方法和報錯總結(jié),小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-04-04
Python調(diào)用C++,通過Pybind11制作Python接口
今天小編就為大家分享一篇關(guān)于Python調(diào)用C++,通過Pybind11制作Python接口,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2018-10-10
Keras load_model 導(dǎo)入錯誤的解決方式
這篇文章主要介紹了Keras load_model 導(dǎo)入錯誤的解決方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-06-06

