import ibm_db

# 连接到 DB2 数据库
dsn_hostname = "192.168.78.30"  # 例如 "db2.server.com"
dsn_port = "50000"              # DB2 实例的端口号，通常为 50000
dsn_database = "SAMPLE"   # 数据库名
dsn_uid = "db2inst1"        # 数据库用户名
dsn_pwd = "Yahua3585668yh"        # 数据库密码

# 构建连接字符串
dsn = (
    f"DATABASE={dsn_database};"
    f"HOSTNAME={dsn_hostname};"
    f"PORT={dsn_port};"
    f"PROTOCOL=TCPIP;"
    f"UID={dsn_uid};"
    f"PWD={dsn_pwd};"
)

try:
    # 连接到数据库
    conn = ibm_db.connect(dsn, "", "")
    print("Connected to DB2 Database")
except Exception as e:
    print(f"Unable to connect: {e}")
