Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 0 Fork 1

JackTang198/CS-Java-LearnNotes

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
Tags (1)
master
2020年09月30日
master
Branches (1)
Tags (1)
master
2020年09月30日
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
Tags (1)
master
2020年09月30日
CS-Java-LearnNotes
/
Python
/
python-src
/
optsqlite3basic.py
CS-Java-LearnNotes
/
Python
/
python-src
/
optsqlite3basic.py
optsqlite3basic.py 3.07 KB
Copy Edit Raw Blame History
prayjourney authored 2021年11月26日 00:40 +08:00 . 🎇update
# -*- coding: utf-8 -*-
# sqlite3模块的学习和使用
import os
import sqlite3
print(os.getcwd())
print(os.listdir())
if os.path.exists("my_sqlite_test.db"):
os.remove("my_sqlite_test.db")
else:
# 打开(不存在时候创建)数据库
sjk = sqlite3.connect("my_sqlite_test.db")
# 创建游标
cu = sjk.cursor()
# 使用游标对象,操作SQL语句查询数据库,获得查询对象
# 基本上sqlite3之中一切都是由游标操作的
# 游标对象有以下的操作:
# execute()--执行sql语句
# executemany--执行多条sql语句
# close()--关闭游标
# fetchone()--从结果中取一条记录,并将游标指向下一条记录
# fetchmany()--从结果中取多条记录
# fetchall()--从结果中取出所有记录
# scroll()--游标滚动
# 创建表
cu.execute("create table people_tb(id integer primary key,pid integer," +
"name varchar(10) unique, age integer, info text NULL)")
# 插入数据
cu.execute("INSERT INTO people_tb(id,pid,name,age,info) VALUES(1,1,'张三',62,'河北石家庄人')")
cu.execute("INSERT INTO people_tb(id,pid,name,age,info) VALUES(2,2,'李四',12,'吉林铁岭人')")
cu.execute("INSERT INTO people_tb(id,pid,name,age,info) VALUES(3,3,'Jhon Sm',32,'美国纽约人')")
cu.execute("INSERT INTO people_tb(id,pid,name,age,info) VALUES(4,4,'Maimaiti',28,'新疆喀什人')")
cu.execute("INSERT INTO people_tb(id,pid,name,age,info) VALUES(5,5,'Rain',26,'韩国大邱人')")
sjk.commit() # 提交
##查询
cu.execute("SELECT * FROM people_tb") # 要提取查询到的数据,使用游标的fetch***函数,如:
print(cu.fetchall())
print("===========")
# 修改
cu.execute("UPDATE people_tb SET name='萨克斯' WHERE id= 2")
cu.execute("UPDATE people_tb SET age=27 WHERE id= 4")
sjk.commit() # 提交
# 插入,查询
cu.execute("INSERT INTO people_tb VALUES(6,6,'鸠摩智',52,'西藏拉萨人')")
cu.execute("INSERT INTO people_tb VALUES(7,7,'郭靖',42,'湖北襄阳人')")
sjk.commit()
# 占位符的使用
sql1 = "insert into people_tb values(?,?,?,?,?)"
# sql2='insert into people_tb (id,pid,name,age,info) values(%d, %d, %s, %d, %s)'
cu.execute(sql1, (9, 9, '杨过', 22, '陕西西安人'))
# cu.execute(sql2,(10,10,'杀马特',22,'四川成都人'))
# executemany的使用
li = [(11, 11, '马超22', 24, '甘肃武威人'), (12, 12, '诸葛亮22', 23, '河南南阳人'), (13, 13, '周瑜22', 22, '浙江绍兴人')]
cu.executemany(sql1, li)
sjk.commit()
cu.execute("SELECT * FROM people_tb") # 要提取查询到的数据,使用游标的fetch***函数,如:
print(cu.fetchall())
print("===========")
de_sql = "delete from people_tb where id=?"
no = [(6,), (7,), (9,), (10,), (11,), (12,), (13,)]
cu.executemany(de_sql, no)
sjk.commit()
# 删除
cu.execute("DELETE FROM people_tb WHERE name='鸠摩智1'")
cu.execute("SELECT * FROM people_tb") # 要提取查询到的数据,使用游标的fetch***函数,如:
print(cu.fetchall())
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

不断总结的计算机基础,编程相关的基本技能、技巧、方法、知识点与学习笔记
No labels
BSD-3-Clause
Use BSD-3-Clause
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/JackTang198/CS-Java-LearnNotes.git
git@gitee.com:JackTang198/CS-Java-LearnNotes.git
JackTang198
CS-Java-LearnNotes
CS-Java-LearnNotes
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /