zoukankan      html  css  js  c++  java
  • Python测试DB2连通性

    Python测试数据库连通性:

    #!/usr/bin/python27
    #encoding: utf-8
    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
    
    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)
    
    if __name__ == "__main__":
        file_path = os.path.join(os.path.split(os.path.realpath(__file__))[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)
    

     db.cfg

    PTEST1,192.168.2.180,50000,db2inst1,db2inst1
    PTEST,192.168.2.180,50001,db2inst1,db2inst1
    
    PTEST2,192.168.2.180,50000,db2inst1,db2inst1
    
  • 相关阅读:
    fork()和僵尸进程
    布尔变量面试题
    vue学习之二
    vue学习之一
    圈复杂度
    phpExcel与jq的ajax
    Object.defineProperty与修改某个数组实现监听效果
    mpn不得不说的坑
    论javascript编写优美
    微信小程序之学习
  • 原文地址:https://www.cnblogs.com/jjzd/p/7382877.html
Copyright © 2011-2022 走看看