|
25 | 25 | # handle database request and query city information |
26 | 26 | def city(name=None): |
27 | 27 | # connect to DB2 |
28 | | - db2conn = ibm_db.connect(db2cred['ssldsn'], "","") |
29 | | - if db2conn: |
30 | | - # we have a Db2 connection, query the database |
31 | | - sql="select * from cities where name=? order by population desc" |
32 | | - # Note that for security reasons we are preparing the statement first, |
33 | | - # then bind the form input as value to the statement to replace the |
34 | | - # parameter marker. |
35 | | - stmt = ibm_db.prepare(db2conn,sql) |
36 | | - ibm_db.bind_param(stmt, 1, name) |
37 | | - ibm_db.execute(stmt) |
38 | | - rows=[] |
39 | | - # fetch the result |
40 | | - result = ibm_db.fetch_assoc(stmt) |
41 | | - while result != False: |
42 | | - rows.append(result.copy()) |
43 | | - result = ibm_db.fetch_assoc(stmt) |
44 | | - # close database connection |
45 | | - ibm_db.close(db2conn) |
46 | | - return render_template('city.html', ci=rows) |
| 28 | + rows=[] |
| 29 | + try: |
| 30 | + db2conn = ibm_db.connect(db2cred['ssldsn'], "","") |
| 31 | + if db2conn: |
| 32 | + # we have a Db2 connection, query the database |
| 33 | + sql="select * from cities where name=? order by population desc" |
| 34 | + # Note that for security reasons we are preparing the statement first, |
| 35 | + # then bind the form input as value to the statement to replace the |
| 36 | + # parameter marker. |
| 37 | + stmt = ibm_db.prepare(db2conn,sql) |
| 38 | + ibm_db.bind_param(stmt, 1, name) |
| 39 | + ibm_db.execute(stmt) |
| 40 | + # fetch the result |
| 41 | + result = ibm_db.fetch_assoc(stmt) |
| 42 | + while result != False: |
| 43 | + rows.append(result.copy()) |
| 44 | + result = ibm_db.fetch_assoc(stmt) |
| 45 | + # close database connection |
| 46 | + ibm_db.close(db2conn) |
| 47 | + return render_template('city.html', ci=rows) |
| 48 | + except: |
| 49 | + return "Db2 connection issues" |
| 50 | + |
47 | 51 |
|
48 | 52 | # main page to dump some environment information |
49 | 53 | @app.route('/') |
|
0 commit comments