38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
#!/users/dsc/bin/Python3
|
|
#-*-coding: UTF-8 -*-
|
|
import ibm_db
|
|
import json
|
|
import os
|
|
#系统环境变量
|
|
envs = os.environ
|
|
CRGS_dir = envs["CRGS"]
|
|
print(CRGS_dir)
|
|
print('{CRGS}/config/config.json'.format(CRGS=CRGS_dir))
|
|
db2_config = ''
|
|
with open('{CRGS}/config/config.json'.format(CRGS=CRGS_dir),
|
|
'r',
|
|
encoding='utf8') as fp:
|
|
json_data = json.load(fp)
|
|
db2_config = json_data['utility']['db2']
|
|
dbinfo = (
|
|
"DATABASE={dbname};HOSTNAME={dbhost};PORT={port};PROTOCOL=TCPIP;UID={username};PWD={passwd}"
|
|
.format(dbname=db2_config["database"],
|
|
dbhost="DBHOST",
|
|
port="50000",
|
|
username=db2_config["username"],
|
|
passwd=db2_config["password"])) #数据库信息
|
|
try:
|
|
conn = ibm_db.connect(dbinfo,'','') #连接数据库
|
|
sql = "SELECT RULEID,RULENAME FROM T_RULE_CFG"
|
|
stmt = ibm_db.exec_immediate(conn, sql)
|
|
# dictionary = ibm_db.fetch_both(stmt)
|
|
|
|
while ibm_db.fetch_row(stmt) != False:
|
|
print("ruleid : ", ibm_db.result(stmt, "RULEID"))
|
|
print("rulename : ", ibm_db.result(stmt, "RULENAME"))
|
|
|
|
|
|
except:
|
|
print("connect faild,%s "% ibm_db.conn_errormesg())
|
|
|
|
ibm_db.close(conn) |