zoukankan      html  css  js  c++  java
  • 2021年4月4日

    时间:1个小时左右

    代码:200行左右

    博客:1

    知识点:疫情数据入库后的增删改查操作

    import pymysql
    
    from day_04 import utils
    
    
    # 查询
    
    def query():
        # 获取数据库的连接
        conn, cursor = utils.get_conn()
        sql = 'select * from student'
        cursor.execute(sql)
        connect = cursor.fetchall()
        print(connect)
        # 释放资源
        utils.close(conn, cursor)
    
    
    # 插入数据
    def insert():
        # 获取数据库的连接
        conn, cursor = utils.get_conn()
        sql = 'insert into student values(null,"siyu",17,"python",78)'
        cursor.execute(sql)
    
        # 提交事务
        conn.commit()
        # 释放资源
        utils.close(conn, cursor)
    
    
    # 更新数据
    
    def updata():
        # 获取数据库的连接
        conn, cursor = utils.get_conn()
        sql = 'update student set name="wangwu" where id=2'
        cursor.execute(sql)
        conn.commit()
        # 释放资源
        utils.close(conn, cursor)
    
    
    # 删除
    
    def delete():
        # 获取数据库的连接
        conn, cursor = utils.get_conn()
        sql = 'delete from student where id=2'
        cursor.execute(sql)
        conn.commit()
        # 释放资源
        utils.close(conn, cursor)
    
    
    if __name__ == "__main__":
        query()
        insert()
        # delete()
        # query()
  • 相关阅读:
    Java学习之路----计算圆形的面积和周长
    数据库系统的基本组成内容
    软件测试的含义以及测试的对象
    wg sync.WaitGroup执行顺序
    go channel
    字符串操作
    scanf
    py停止工作
    jira索引失败
    py kafka
  • 原文地址:https://www.cnblogs.com/j-y-s/p/14903254.html
Copyright © 2011-2022 走看看