Advertisement
Guest User

Untitled

a guest
Oct 9th, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {},
  7. "outputs": [],
  8. "source": [
  9. "import ibm_db"
  10. ]
  11. },
  12. {
  13. "cell_type": "code",
  14. "execution_count": 2,
  15. "metadata": {},
  16. "outputs": [],
  17. "source": [
  18. "#Replace the placeholder values with your actual Db2 hostname, username, and password:\n",
  19. "dsn_hostname = \"dashdb-txn-sbox-yp-lon02-02.services.eu-gb.bluemix.net\" # e.g.: \"dashdb-txn-sbox-yp-dal09-04.services.dal.bluemix.net\"\n",
  20. "dsn_uid = \"YOURUSERID\" # e.g. \"abc12345\"\n",
  21. "dsn_pwd = \"YOURPASSWORD\" # e.g. \"7dBZ3wWt9XN6$o0J\"\n",
  22. "\n",
  23. "dsn_driver = \"{IBM DB2 ODBC DRIVER}\"\n",
  24. "dsn_database = \"BLUDB\" # e.g. \"BLUDB\"\n",
  25. "dsn_port = \"50000\" # e.g. \"50000\" \n",
  26. "dsn_protocol = \"TCPIP\" # i.e. \"TCPIP\""
  27. ]
  28. },
  29. {
  30. "cell_type": "code",
  31. "execution_count": 3,
  32. "metadata": {},
  33. "outputs": [
  34. {
  35. "name": "stdout",
  36. "output_type": "stream",
  37. "text": [
  38. "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=BLUDB;HOSTNAME=dashdb-txn-sbox-yp-lon02-02.services.eu-gb.bluemix.net;PORT=50000;PROTOCOL=TCPIP;UID=rxl00035;PWD=rbr+mmp2s25dkpv4;\n"
  39. ]
  40. }
  41. ],
  42. "source": [
  43. "#DO NOT MODIFY THIS CELL. Just RUN it with Shift + Enter\n",
  44. "#Create the dsn connection string\n",
  45. "dsn = (\n",
  46. " \"DRIVER={0};\"\n",
  47. " \"DATABASE={1};\"\n",
  48. " \"HOSTNAME={2};\"\n",
  49. " \"PORT={3};\"\n",
  50. " \"PROTOCOL={4};\"\n",
  51. " \"UID={5};\"\n",
  52. " \"PWD={6};\").format(dsn_driver, dsn_database, dsn_hostname, dsn_port, dsn_protocol, dsn_uid, dsn_pwd)\n",
  53. "\n",
  54. "#print the connection string to check correct values are specified\n",
  55. "print(dsn)"
  56. ]
  57. },
  58. {
  59. "cell_type": "code",
  60. "execution_count": 4,
  61. "metadata": {},
  62. "outputs": [
  63. {
  64. "name": "stdout",
  65. "output_type": "stream",
  66. "text": [
  67. "Connected to database: BLUDB as user: rxl00035 on host: dashdb-txn-sbox-yp-lon02-02.services.eu-gb.bluemix.net\n"
  68. ]
  69. }
  70. ],
  71. "source": [
  72. "#DO NOT MODIFY THIS CELL. Just RUN it with Shift + Enter\n",
  73. "#Create database connection\n",
  74. "\n",
  75. "try:\n",
  76. " conn = ibm_db.connect(dsn, \"\", \"\")\n",
  77. " print (\"Connected to database: \", dsn_database, \"as user: \", dsn_uid, \"on host: \", dsn_hostname)\n",
  78. "\n",
  79. "except:\n",
  80. " print (\"Unable to connect: \", ibm_db.conn_errormsg() )"
  81. ]
  82. },
  83. {
  84. "cell_type": "code",
  85. "execution_count": 5,
  86. "metadata": {},
  87. "outputs": [
  88. {
  89. "name": "stdout",
  90. "output_type": "stream",
  91. "text": [
  92. "DBMS_NAME: DB2/LINUXX8664\n",
  93. "DBMS_VER: 11.01.0404\n",
  94. "DB_NAME: BLUDB\n"
  95. ]
  96. }
  97. ],
  98. "source": [
  99. "server = ibm_db.server_info(conn)\n",
  100. "\n",
  101. "print (\"DBMS_NAME: \", server.DBMS_NAME)\n",
  102. "print (\"DBMS_VER: \", server.DBMS_VER)\n",
  103. "print (\"DB_NAME: \", server.DB_NAME)"
  104. ]
  105. },
  106. {
  107. "cell_type": "code",
  108. "execution_count": 6,
  109. "metadata": {},
  110. "outputs": [
  111. {
  112. "name": "stdout",
  113. "output_type": "stream",
  114. "text": [
  115. "DRIVER_NAME: libdb2.a\n",
  116. "DRIVER_VER: 11.01.0404\n",
  117. "DATA_SOURCE_NAME: BLUDB\n",
  118. "DRIVER_ODBC_VER: 03.51\n",
  119. "ODBC_VER: 03.01.0000\n",
  120. "ODBC_SQL_CONFORMANCE: EXTENDED\n",
  121. "APPL_CODEPAGE: 1208\n",
  122. "CONN_CODEPAGE: 1208\n"
  123. ]
  124. }
  125. ],
  126. "source": [
  127. "#Retrieve Metadata for the Database Client / Driver\n",
  128. "client = ibm_db.client_info(conn)\n",
  129. "\n",
  130. "print (\"DRIVER_NAME: \", client.DRIVER_NAME) \n",
  131. "print (\"DRIVER_VER: \", client.DRIVER_VER)\n",
  132. "print (\"DATA_SOURCE_NAME: \", client.DATA_SOURCE_NAME)\n",
  133. "print (\"DRIVER_ODBC_VER: \", client.DRIVER_ODBC_VER)\n",
  134. "print (\"ODBC_VER: \", client.ODBC_VER)\n",
  135. "print (\"ODBC_SQL_CONFORMANCE: \", client.ODBC_SQL_CONFORMANCE)\n",
  136. "print (\"APPL_CODEPAGE: \", client.APPL_CODEPAGE)\n",
  137. "print (\"CONN_CODEPAGE: \", client.CONN_CODEPAGE)"
  138. ]
  139. },
  140. {
  141. "cell_type": "code",
  142. "execution_count": 7,
  143. "metadata": {},
  144. "outputs": [
  145. {
  146. "data": {
  147. "text/plain": [
  148. "True"
  149. ]
  150. },
  151. "execution_count": 7,
  152. "metadata": {},
  153. "output_type": "execute_result"
  154. }
  155. ],
  156. "source": [
  157. "ibm_db.close(conn)"
  158. ]
  159. },
  160. {
  161. "cell_type": "code",
  162. "execution_count": null,
  163. "metadata": {},
  164. "outputs": [],
  165. "source": []
  166. }
  167. ],
  168. "metadata": {
  169. "kernelspec": {
  170. "display_name": "Python",
  171. "language": "python",
  172. "name": "conda-env-python-py"
  173. },
  174. "language_info": {
  175. "codemirror_mode": {
  176. "name": "ipython",
  177. "version": 3
  178. },
  179. "file_extension": ".py",
  180. "mimetype": "text/x-python",
  181. "name": "python",
  182. "nbconvert_exporter": "python",
  183. "pygments_lexer": "ipython3",
  184. "version": "3.6.7"
  185. }
  186. },
  187. "nbformat": 4,
  188. "nbformat_minor": 4
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement