64 DB2 UDB for Linux on iSeries: Implementation Guide
Figure 3-25 ODBC driver and ODBC driver manager
The ODBC driver manager is a management facility which mediates the
application program and each ODBC driver. The ODBC driver is the RDBMS
dependent module to enable access to each database via ODBC.
On the Windows platform, the ODBC driver manager is provided as part of the
operating system, but on Linux there is no system-provided ODBC driver
manager. Although there are a number of open source or commercial ODBC
driver managers on the Linux platform, the open source unixODBC
(http://www.unixODBC.org/) is the formally supported ODBC driver manager of
DB2 UDB and DB2 Connect on Linux.
The ODBC driver to access DB2 is provided as a part of DB2 UDB or DB2
Connect product. Actually, the CLI library libdb2.so itself can be used as the
ODBC driver for DB2.
3.6.1 ODBC setup
First, we have to setup the ODBC environment, such as the ODBC driver
manager and data sources. SLES8 includes unixODBC-2.2.2-57 package and
unixODBC-devel-2.2.2-57 package. We use the unixODBC-2.2.2-57 as the driver
manager and unixODBC-devel-2.2.2-57 as the development package. The
devel
package is necessary to compile the ODBC application program.
Linux Application
written to ODBC API
ODBC Driver Manager for Linux
(unixODBC)
MySQL
ODBC Driver
PostgreSQL
ODBC Driver
LinuxOS/400
DB2 UDB
for iSeries
DRDA
DB2
ODBC Driver
Chapter 3. Connectivity with DB2 UDB for iSeries 65
The unixODBC usually has some other GUI applications, such as ODBCConfig
(Configuration tool) or Datamanager (Test tool) but they are not included in
SLES8. If you want to use these, you need to download the additional (or the full)
packages and install (or make) them. For unixODBC, refer to the Web site:
http://www.unixodbc.org
In this section, we directly update the ODBC configuration files by a text editor.
ODBC Driver Manager
In the default installation of SLES8, the unixODBC driver manager configuration
file is the text file /etc/unixODBC/odbcinst.ini, which is an empty file. We need
to add the lines for the ODBC driver that comes with DB2. In this section, we
refer to that driver as the DB2 ODBC Driver.
To configure the ODBC driver as the root user, using a text editor, add a new
stanza as illustrated in Figure 3-26.
Figure 3-26 Driver manager configuration
The library file libdb2.so is the DB2 ODBC Driver installed with the DB2
product. Actually it is the file we used as the CLI library in 3.5.2, “Compile and
run” on page 61. The DB2 CLI library also can be used as the DB2 ODBC driver.
We named the driver “DB2DRIVER” which is the name of the stanza. You can
choose any name here, but the name must be used in the datasource
configuration file.
ODBC data sources
The data source configuration file is /etc/unixODBC/odbc.ini, for the system
data sources, and ~/.odbc.ini for the user data sources ( ~ is the user’s home
directory). We use the system data source in our scenario.
To add two databases, AS05 on the OS/400 and SAMPLE on the Linux as the
ODBC system data source, edit the /etc/unixODBC/odbc.ini as the root user.
In our example (Figure 3-27), we add two stanzas: [OS400] for the remote
OS/400 database and [SAMPLE] for the local Linux database. These names must
be the same as the database alias registered in the DB2 database directory. The
driver name DB2DRIVER must be the same as the stanza name in the odbcinst.ini
file in Figure 3-26.
[DB2DRIVER]
Description = DB2 ODBC Driver
Driver = /home/db2inst1/sqllib/lib/libdb2.so
66 DB2 UDB for Linux on iSeries: Implementation Guide
Figure 3-27 System data sources configuration
That is all you need to do for the setup. As illustrated in the above example,
configuration is quite simple because all the connection information is held in the
DB2 node or database directory. You just need a few stanzas created in both the
odbcinst.ini and odbc.ini files for the entry of DB2 Connect databases.
Now you are ready to test the ODBC connection over the DB2 ODBC Driver. You
can use “isql” to test the ODBC connection.
[OS400]
Description = OS/400 Host partition AS05
Driver = DB2DRIVER
[SAMPLE]
Description = DB2 local sample database
Driver = DB2DRIVER

Get DB2 for Linux on iSeries: Implementation Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.