-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonDb2Update.py
More file actions
40 lines (31 loc) · 1.14 KB
/
pythonDb2Update.py
File metadata and controls
40 lines (31 loc) · 1.14 KB
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
34
35
36
37
38
39
40
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, "", "")
account = '789171908858486'
if conn:
ibm_db.autocommit(conn, ibm_db.SQL_AUTOCOMMIT_OFF)
sql = "UPDATE BALANCES SET AMOUNT = (AMOUNT * 0.1) + AMOUNT WHERE AC_ID = ?;"
# stmt = ibm_db.exec_immediate(conn, sql)
stmt = ibm_db.prepare(conn, sql)
ibm_db.bind_param(stmt, 1, account)
try:
ibm_db.execute(stmt)
ibm_db.commit(conn)
except:
print(ibm_db.stmt_errormsg())
print('connect not successful')
ibm_db.close(conn)
print("connection closed")