最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Python 操作数据库DB
时间:2026-06-18 09:06:55 编辑:袖梨 来源:一聚教程网
#!/usr/bin/env python# coding=utf-8import ibm_db# 执行DB2 SQL语句try:conn = ibm_db.connect("DATABASE=testdb;HOSTNAME=10.20.10.9;PORT=50000;PROTOCOL=TCPIP;UID=db2inst1;PWD=123456;", "", "")# db2_sql = "SELECT * FROM youtable;"# stmt = ibm_db.exec_immediate(conn, db2_sql)# print "Number of affected rows: ", ibm_db.num_rows(stmt)# ibm_db.close(conn)sql = "SELECT * FROM YOUTABLE"stmt = ibm_db.exec_immediate(conn, sql)dictionary = ibm_db.fetch_both(stmt)while dictionary is not False:print "The ID is : ", dictionary["ID"]print "The USERNAME is : ", dictionary["USERNAME"]dictionary = ibm_db.fetch_both(stmt)except Exception as e:print("connect failed%s" % str(e))
f
相关文章
- Kimi企业版功能介绍:团队协作、文档搜索与API接入范围 06-18
- 静态图片转动态图片的软件推荐|功能全面的GIF与动态图制作工具合集 06-18
- 免费高清热门漫画APP排行榜 漫画大全APP下载推荐 06-18
- 屠龙争霸新手如何玩 06-18
- 照片修复软件推荐 免费与功能全面的照片修复工具精选 06-18
- Twitter官网-twitter网页版入口 06-18