Python+selenium oracle数据库断言

1、新建python文件 connection_db.py
代码:
db = ('database_user/'
'database_password@127.0.0.1:1521/'
'batabase_name')

其中:
database_user:数据库登录名
database_password:数据库登录密码
127.0.0.1:1521     数据库的IP地址:Oracle端口
batabase_name   数据库名

2、新建python文件,业务功能中,例如保存数据时:

# 数据库断言
text = "select * from table_name where ORG_SHORTNAME ="
SQL = "%s'%s'" % (text, "value")
try:
conn = cx_Oracle.connect(db)
cursor = conn.cursor() # 所有的查询,都在连接conn的一个模块cursor上面运行的
cursor.execute(SQL) # 执行SQL语句
row = cursor.fetchone() # 获取查询结果的一行
cursor.close()
conn.close()
if row != None: #查询结果不为空
print("数据库查询到数据")
else:
print("数据库没有增加成功")
except Exception:
print("数据库连接超时")
原文地址:https://www.cnblogs.com/shimo/p/14007235.html