-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonDb2Select.py
More file actions
33 lines (26 loc) · 982 Bytes
/
pythonDb2Select.py
File metadata and controls
33 lines (26 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import ibm_db
database = "SAMPLE"
hostName = "0.0.0.0"
userID = "db2inst1"
passWord = "password"
portNum = "50000"
connString = ''
connString = "DRIVER={IBM DB2 ODBC DRIVER}"
connString += ";ATTACH=FALSE" # Attach To A Server; Not A Database
connString += ";DATABASE=" + database # Ignored When Connecting To A Server
connString += ";HOSTNAME=" + hostName # Required To Connect To A Server
connString += ";PORT=" + portNum # Required To Connect To A Server
connString += ";PROTOCOL=TCPIP" # Required To Connect To A Server
connString += ";UID=" + userID
connString += ";PWD=" + passWord
conn = ibm_db.connect(connString, "", "")
if conn:
sql = "SELECT FIRSTNME FROM EMPLOYEE"
stmt = ibm_db.exec_immediate(conn, sql)
result = ibm_db.fetch_both(stmt)
while result:
print('LAST NAME -> ', result[0])
result = ibm_db.fetch_both(stmt)
print('connect successful')
ibm_db.close(conn)
print("connection closed")