Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [],
- "source": [
- "import ibm_db"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [],
- "source": [
- "#Replace the placeholder values with your actual Db2 hostname, username, and password:\n",
- "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",
- "dsn_uid = \"YOURUSERID\" # e.g. \"abc12345\"\n",
- "dsn_pwd = \"YOURPASSWORD\" # e.g. \"7dBZ3wWt9XN6$o0J\"\n",
- "\n",
- "dsn_driver = \"{IBM DB2 ODBC DRIVER}\"\n",
- "dsn_database = \"BLUDB\" # e.g. \"BLUDB\"\n",
- "dsn_port = \"50000\" # e.g. \"50000\" \n",
- "dsn_protocol = \"TCPIP\" # i.e. \"TCPIP\""
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "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"
- ]
- }
- ],
- "source": [
- "#DO NOT MODIFY THIS CELL. Just RUN it with Shift + Enter\n",
- "#Create the dsn connection string\n",
- "dsn = (\n",
- " \"DRIVER={0};\"\n",
- " \"DATABASE={1};\"\n",
- " \"HOSTNAME={2};\"\n",
- " \"PORT={3};\"\n",
- " \"PROTOCOL={4};\"\n",
- " \"UID={5};\"\n",
- " \"PWD={6};\").format(dsn_driver, dsn_database, dsn_hostname, dsn_port, dsn_protocol, dsn_uid, dsn_pwd)\n",
- "\n",
- "#print the connection string to check correct values are specified\n",
- "print(dsn)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Connected to database: BLUDB as user: rxl00035 on host: dashdb-txn-sbox-yp-lon02-02.services.eu-gb.bluemix.net\n"
- ]
- }
- ],
- "source": [
- "#DO NOT MODIFY THIS CELL. Just RUN it with Shift + Enter\n",
- "#Create database connection\n",
- "\n",
- "try:\n",
- " conn = ibm_db.connect(dsn, \"\", \"\")\n",
- " print (\"Connected to database: \", dsn_database, \"as user: \", dsn_uid, \"on host: \", dsn_hostname)\n",
- "\n",
- "except:\n",
- " print (\"Unable to connect: \", ibm_db.conn_errormsg() )"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "DBMS_NAME: DB2/LINUXX8664\n",
- "DBMS_VER: 11.01.0404\n",
- "DB_NAME: BLUDB\n"
- ]
- }
- ],
- "source": [
- "server = ibm_db.server_info(conn)\n",
- "\n",
- "print (\"DBMS_NAME: \", server.DBMS_NAME)\n",
- "print (\"DBMS_VER: \", server.DBMS_VER)\n",
- "print (\"DB_NAME: \", server.DB_NAME)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "DRIVER_NAME: libdb2.a\n",
- "DRIVER_VER: 11.01.0404\n",
- "DATA_SOURCE_NAME: BLUDB\n",
- "DRIVER_ODBC_VER: 03.51\n",
- "ODBC_VER: 03.01.0000\n",
- "ODBC_SQL_CONFORMANCE: EXTENDED\n",
- "APPL_CODEPAGE: 1208\n",
- "CONN_CODEPAGE: 1208\n"
- ]
- }
- ],
- "source": [
- "#Retrieve Metadata for the Database Client / Driver\n",
- "client = ibm_db.client_info(conn)\n",
- "\n",
- "print (\"DRIVER_NAME: \", client.DRIVER_NAME) \n",
- "print (\"DRIVER_VER: \", client.DRIVER_VER)\n",
- "print (\"DATA_SOURCE_NAME: \", client.DATA_SOURCE_NAME)\n",
- "print (\"DRIVER_ODBC_VER: \", client.DRIVER_ODBC_VER)\n",
- "print (\"ODBC_VER: \", client.ODBC_VER)\n",
- "print (\"ODBC_SQL_CONFORMANCE: \", client.ODBC_SQL_CONFORMANCE)\n",
- "print (\"APPL_CODEPAGE: \", client.APPL_CODEPAGE)\n",
- "print (\"CONN_CODEPAGE: \", client.CONN_CODEPAGE)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "True"
- ]
- },
- "execution_count": 7,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "ibm_db.close(conn)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python",
- "language": "python",
- "name": "conda-env-python-py"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.6.7"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 4
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement