Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Python Uses ibm_db connect to DB2

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

After installing Python and ibm_db, do a few small examples to test

> import ibm_db

> ibm_db.__version__

'2.0.9'

> > >

=

#! / usr/bin/python

# Example 1: Connect to a local or cataloged database

Import ibm_db

Conn = ibm_db.connect ("dsn=SAMPLE", "db2inst1", "dbpwd")

Sql = "SELECT QUOTEID,GEO FROM DB2INST1.TRN fetch first 10 rows only with ur"

Stmt = ibm_db.exec_immediate (conn, sql)

Dictionary = ibm_db.fetch_both (stmt)

While dictionary! = False:

Print (dictionary ["QUOTEID"])

Print (dictionary ["GEO"])

Dictionary = ibm_db.fetch_both (stmt)

=

#! / usr/bin/python

Example 2: Connect to an uncataloged database

Import ibm_db

Conn = ibm_db.connect ("DATABASE=SAMPLE;HOSTNAME=192.168.101.133;PORT=60006;PROTOCOL=TCPIP;UID=db2inst1;PWD=dbpwd;", "", ")

Sql = "SELECT QUOTEID,GEO FROM DB2INST1.TRN fetch first 10 rows only with ur"

Stmt = ibm_db.exec_immediate (conn, sql)

Dictionary = ibm_db.fetch_both (stmt)

While dictionary! = False:

Print (dictionary ["QUOTEID"])

Print (dictionary ["GEO"])

Dictionary = ibm_db.fetch_both (stmt)

=

#! / usr/bin/python

# Example 3: Connect to an uncataloged database with SSL enabled

Import ibm_db

Conn = ibm_db.connect ("DATABASE=SAMPLE;HOSTNAME=192.168.101.133;PORT=50001;SECURITY=SSL;UID=db2inst1;PWD=dbpwd;SSLServerCertificate=/home/db2inst1/db2_ssl/db2_ssl_keydb.arm;", "", ")

Sql = "SELECT QUOTEID,GEO FROM DB2INST1.TRN fetch first 10 rows only with ur"

Stmt = ibm_db.exec_immediate (conn, sql)

Dictionary = ibm_db.fetch_both (stmt)

While dictionary! = False:

Print (dictionary ["QUOTEID"])

Print (dictionary ["GEO"])

Dictionary = ibm_db.fetch_both (stmt)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report