Step-by-step instructions for connecting Python to DB2 express-c

Source: Internet
Author: User
Tags command line db2 db2 express python script


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.





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.