zoukankan      html  css  js  c++  java
  • python体验(05).python处理sqlite数据库

    python处理sqlite数据库
    1、检查用户环境是否安装sqlite
            aptitude show sqlite3
    2、创建数据库,添加表并插入数据
            sqlite3 myfamily
            create table people(id int, name varchar(30), age int, sex char(1));
            
    insert into people values(0,'Zihao Xu',5,'M');
            
    select * from people;.exit;
    3、编写代码
     phoenix@debian:~/py/database$ cat sqlite.py
    #!/usr/bin/python
    #
    filename:sqlite.py
    #
    import sqlite3                          #import sqlite3 module
    con = sqlite3.connect('myfamily')       #connect to the database
    cur = con.cursor()                      #get the database cursor
    cur.execute('insert into people(id,name,age,sex)' +
            
    ' values(99,\'temp\',99,\'F\')')
    = cur.execute('delete from people where age=99')
    con.commit()
    cur.execute(
    'select * from people')
    = cur.fetchall()
    print s
    cur.close()
    con.close()


  • 相关阅读:
    CKeditor3.6.2 配置与精简
    CKEditor与CKFinder整合并实现文件上传功能
    实体关联关系映射:
    status pending状态
    wx:for
    小程序
    获取指定控件的值
    报表
    dataGridView 设置
    SQLite 的使用
  • 原文地址:https://www.cnblogs.com/flaaash/p/1894567.html
Copyright © 2011-2022 走看看