Python is a very powerful, versatile, advanced, object-oriented, dynamic type programming language that is easy to read and understand, and it's interesting to write programs with it. To make it more exciting, we want to be able to connect it to the same powerful and inexpensive ibm®db2® core engine version. DB2 Express-c is a free data server that can be used for development and deployment, which enables us to achieve this aspiration. This step-by-step article describes all the acquisition, installation, and configuration steps required to use the Python connection and use the DB2 express-c instance.
Overview
The following are the tasks to be performed in this article:
Get and install Python
Get and install DB2 express-c
To create a sample database
Use DB2 control Center to view detailed information about a database
View some table contents using DB2 Command line Processor
Set up Windows®odbc Datasource for the sample database
Get and install the Python MXODBC package
Using MXODBC to access a database in a Python script
First, install the Python
Python is a programming language that is easy to read, use, and learn. This language has many attractive benefits, the most important of which is easy to read. One of the most interesting aspects for beginners of this language is that whitespace (indentation) is meaningful. This means that the compiler/interpreter interprets the code snippet in Listing 1 in the same way that people understand it.
Listing 1. Indentation is meaningful.1| if ( a == b ) :
2| if ( c == d ) :
3| print 'both match' # printed only when both comparisons are true
4| else :
5| print 'a not equal b'
Note: Line numbers are used only for reference purposes.
The If statement on line 1th compares the values of variables a and B. If they are equal, the statements on line 2nd are executed. The output generated by line 3rd is seen only if the value of variable a equals variable B and the value of variable c equals variable D. Another print statement (line 5th) executes only if the value of a is not equal to B, regardless of the value of C and D.
If you are not familiar with the Python language, then you should consider learning it.