# File Named "ipynb_exit.py"; This Class Contains The Programming Logic Needed To Allow "exit()" # # Functionality To Work Without Raising An Error Or Stopping The Kernel If The Application Is # # Invoked In A Jupyter Notebook # #-------------------------------------------------------------------------------------------------# from ipynb_exit import exit # Define And Initialize The Appropriate Variables dbName = "SAMPLE" userID = "db2inst1" passWord = "******" dbConnection = None resultSet = False numColumns = False # Create An Instance Of The Db2ConnectionMgr Class And Use It To Connect To A Db2 Database conn = Db2ConnectionMgr('DB', dbName, '', '', userID, passWord) conn.openConnection() if conn.returnCode is True: dbConnection = conn.connectionID else: conn.closeConnection() exit(-1) # Define The SQL Statement That Is To Be Executed sqlStatement = "SELECT * FROM emp_resume" # Execute The SQL Statement Just Defined print("Executing the SQL statement \"" + sqlStatement + "\" ... ", end="") try: resultSet = ibm_db.exec_immediate(dbConnection, sqlStatement) except Exception:
# Import The ipynb_exit Class Definition, Attributes, And Methods That Have Been Defined In The # # File Named "ipynb_exit.py"; This Class Contains The Programming Logic Needed To Allow "exit()" # # Functionality To Work Without Raising An Error Or Stopping The Kernel If The Application Is # # Invoked In A Jupyter Notebook # #-------------------------------------------------------------------------------------------------# from ipynb_exit import exit # Define And Initialize The Appropriate Variables userID = "db2inst1" # User ID (Recognized By The Local Server) passWord = "******" # User Password svrConnection = None dbName = "MY_DB" returnCode = False # Create An Instance Of The Db2ConnectionMgr Class And Use It To Connect To The Local Db2 Server conn = Db2ConnectionMgr('LOCAL_SVR', '', '', '', userID, passWord) conn.openConnection() if conn.returnCode is True: svrConnection = conn.connectionID else: conn.closeConnection() exit(-1) # Attempt To Create A New Database At The Local Server print("Creating a database named " + dbName + " at the local server. Please wait.") try: returnCode = ibm_db.createdbNX(svrConnection, dbName) except Exception: pass
# Functionality To Work Without Raising An Error Or Stopping The Kernel If The Application Is # # Invoked In A Jupyter Notebook # #-------------------------------------------------------------------------------------------------# from ipynb_exit import exit # Define And Initialize The Appropriate Variables hostName = "197.126.80.22" # IP Address Of A Remote Server portNum = "50000" # Port Number Used By Db2 userID = "db2inst2" # User ID (Recognized By The Remote Server) passWord = "******" # User Password svrConnection = None dbName = "MY_DB" returnCode = False # Create An Instance Of The Db2ConnectionMgr Class And Use It To Connect To A Remote Db2 Server conn = Db2ConnectionMgr('SERVER', '', hostName, portNum, userID, passWord) conn.openConnection() if conn.returnCode is True: svrConnection = conn.connectionID else: conn.closeConnection() exit(-1) # Attempt To Delete (Drop) A Database At The Remote Server print("Dropping a database named " + dbName + " at the " + hostName + " server. Please wait.") try: returnCode = ibm_db.dropdb(svrConnection, dbName) except Exception: pass
# Import The ipynb_exit Class Definition, Attributes, And Methods That Have Been Defined In The # # File Named "ipynb_exit.py"; This Class Contains The Programming Logic Needed To Allow "exit()" # # Functionality To Work Without Raising An Error Or Stopping The Kernel If The Application Is # # Invoked In A Jupyter Notebook # #-------------------------------------------------------------------------------------------------# from ipynb_exit import exit # Define And Initialize The Appropriate Variables dbName = "SAMPLE" userID = "db2inst1" passWord = "******" svrConnection = None clientInfo = False # Create An Instance Of The Db2ConnectionMgr Class And Use It To Connect To A Db2 Server conn = Db2ConnectionMgr('SERVER', dbName, '', '', userID, passWord) conn.openConnection() if conn.returnCode is True: svrConnection = conn.connectionID else: conn.closeConnection() exit(-1) # Attempt To Obtain Information About The Db2 Client Being Used print("Obtaining information about the Db2 client ... ", end="") try: clientInfo = ibm_db.client_info(svrConnection) except Exception: pass # If Information About The Client Could Not Be Obtained, Display An Error Message