Python测试DB2连通性

Python测试数据库连通性:

python;gutter:true;</p> <h1>!/usr/bin/python27</h1> <h1>encoding: utf-8</h1> <p>import ibm_db import os import sys def find_db(filename,db_name): f = open(filename) for line in f: file_db = line.strip().split(',')[0] if file_db == db_name: db_list = line.strip().split(',') break f.close() return db_list</p> <p>def test_conn(db_name,db_host,db_port,db_user,db_pwd): db2 = "DATABASE=%s;HOSTNAME=%s;PORT=%s;PROTOCOL=TCPIP;UID=%s;PWD=%s;" %(db_name,db_host,db_port,db_user,db_pwd) try: conn = ibm_db.connect(db2, "", "") except: print "0" else: print "1" ibm_db.close(conn)</p> <p>if <strong>name</strong> == "<strong>main</strong>": file_path = os.path.join(os.path.split(os.path.realpath(<strong>file</strong>))[0],'db1.cfg') conn_db = find_db(file_path,sys.argv[1]) db_name,db_host,db_port,db_user,db_pwd = tuple(conn_db) test_conn(db_name,db_host,db_port,db_user,db_pwd)</p> <pre><code> db.cfg ;gutter:true;
PTEST1,192.168.2.180,50000,db2inst1,db2inst1
PTEST,192.168.2.180,50001,db2inst1,db2inst1

PTEST2,192.168.2.180,50000,db2inst1,db2inst1

Original: https://www.cnblogs.com/jjzd/p/7382877.html
Author: 浮沉一梦
Title: Python测试DB2连通性

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/10674/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

免费咨询
免费咨询
扫码关注
扫码关注
联系站长

站长Johngo!

大数据和算法重度研究者!

持续产出大数据、算法、LeetCode干货,以及业界好资源!

2022012703491714

微信来撩,免费咨询:xiaozhu_tec

分享本页
返回顶部
最近整理资源【免费获取】:   👉 程序员最新必读书单  | 👏 互联网各方向面试题下载 | ✌️计算机核心资源汇总