1 Star 0 Fork 0

zdyumath/playwright_demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
demo03_连接Oracle数据库.py 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
zdyumath 提交于 2023-07-31 18:42 . 修改服务器地址,以防泄露
import oracledb
un = 'esun'
pw = 'Oraclebice502'
cs = 'www.xxxx.net:1527/esun'
def test_select() -> None:
with oracledb.connect(user=un, password=pw, dsn=cs) as connection:
with connection.cursor() as cursor:
sql = """select deptno, dname, loc from dept"""
cursor.execute(sql)
# 获取表结构,用于组装JSON
columns = [col[0] for col in cursor.description]
cursor.rowfactory = lambda *args: dict(zip(columns, args))
result = cursor.fetchall() # 获取全部返回值
print(result)
print(result[1]["LOC"])
def test_insert() -> None:
with oracledb.connect(user=un, password=pw, dsn=cs) as connection:
with connection.cursor() as cursor:
sql = """insert into dept(DNAME, LOC) values (:dname, :loc)"""
try:
ret = cursor.execute(sql, ['MANAGER2', 'BEIJING2'])
except:
print("程序异常")
connection.commit() # 提交操作
def test_delete() -> None:
with oracledb.connect(user=un, password=pw, dsn=cs) as connection:
with connection.cursor() as cursor:
sql = """delete from dept where DEPTNO > 40"""
try:
ret = cursor.execute(sql)
except:
print("程序异常")
connection.commit() # 提交操作
test_select()
test_delete()
test_select()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zdyumath/playwright_demo.git
git@gitee.com:zdyumath/playwright_demo.git
zdyumath
playwright_demo
playwright_demo
master

搜索帮助