ibm.com/redbooks
IBM Informix
Developer’s Handbook
Whei-Jen Chen
Krishna Doddi
Manoj Ghogale
David Jay
Javier Sagrera
Learn application development with
supported APIs, drivers, and interfaces
Understand Informix supported
programming environments
Follow practical examples to
develop an Informix application
Front cover
IBM Informix Developer’s Handbook
October 2010
International Technical Support Organization
SG24-7884-00
© Copyright International Business Machines Corporation 2010. All rights reserved.
Note to U.S. Government Users Restricted Rights -- Use, duplication or disclosure restricted by GSA ADP
Schedule Contract with IBM Corp.
First Edition (October 2010)
This edition applies to IBM Informix Version 11.5.
Note: Before using this information and the product it supports, read the information in
“Notices” on page ix.
© Copyright IBM Corp. 2010. All rights reserved. iii
Contents
Notices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . x
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
The team who wrote this book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Now you can become a published author, too! . . . . . . . . . . . . . . . . . . . . . . . . xiii
Comments welcome. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiv
Stay connected to IBM Redbooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiv
Chapter 1. Introduction to IBM Informix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Server options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1.1 Informix servers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Informix tools for developers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.2.1 Informix Connect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.2.2 Informix Client Software Development Kit. . . . . . . . . . . . . . . . . . . . . . 9
1.2.3 4GL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.2.4 Ruby on Rails . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.2.5 Informix DataBlade Developers Kit . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.2.6 Informix Spatial DataBlade . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.2.7 PHP on Informix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.3 Informix overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.3.1 Architecture overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.3.2 Informix developer environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1.3.3 Informix capabilities. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Chapter 2. Setting up an Informix development environment . . . . . . . . . 25
2.1 Server setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.1.1 Planning for the installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.1.2 Installing Informix Server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.1.3 Configuring Informix Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.2 Client setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.2.1 Informix Client options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.2.2 Installing and setting up Client SDK . . . . . . . . . . . . . . . . . . . . . . . . . 36
2.2.3 Setting up IBM Data Server drivers. . . . . . . . . . . . . . . . . . . . . . . . . . 43
2.2.4 Setting up Informix JDBC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Chapter 3. Working with the ODBC driver . . . . . . . . . . . . . . . . . . . . . . . . . 57
3.1 ODBC and Informix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
iv IBM Informix Developer’s Handbook
3.2 Setup and configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
3.2.1 IBM Informix ODBC Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
3.2.2 IBM Data Server Driver for ODBC and CLI . . . . . . . . . . . . . . . . . . . . 70
3.2.3 Verifying connectivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
3.3 Developing an ODBC application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
3.3.1 Connecting to the database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
3.3.2 Type mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
3.3.3 Performing database operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
3.3.4 Handling special data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
3.3.5 Error handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
3.3.6 Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Chapter 4. Working with ESQL/C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
4.1 Informix ESQL/C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
4.2 Setup and configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
4.3 Windows system configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
4.4 Developing an ESQL/C application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
4.4.1 Creating an ESQL/C application . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
4.4.2 Performing database operations . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
4.4.3 Data types mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
4.4.4 Handling special data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
4.4.5 Exception handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
4.4.6 Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Chapter 5. Working with the JDBC drivers . . . . . . . . . . . . . . . . . . . . . . . . 153
5.1 JDBC drivers for an Informix database . . . . . . . . . . . . . . . . . . . . . . . . . . 154
5.1.1 IBM Informix JDBC Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
5.1.2 IBM Data Server Driver for JDBC and SQLJ . . . . . . . . . . . . . . . . . 156
5.2 Setup and configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
5.2.1 Configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
5.2.2 Verify connectivity with Informix JDBC Driver . . . . . . . . . . . . . . . . . 158
5.2.3 Verify connectivity with the Data Server Driver . . . . . . . . . . . . . . . . 160
5.3 JDBC type mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
5.4 Performing database operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
5.4.1 Connection to the database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
5.4.2 Manipulating data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
5.5 Informix additional features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
5.5.1 Batch inserts or updates and using ResultSet metadata . . . . . . . . 175
5.5.2 BIGSERIAL data type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
5.5.3 Informix smart large objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
5.5.4 Secure Socket Layer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
5.6 Typical errors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
5.6.1 Class not found errors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Contents v
5.6.2 Connectivity errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
5.6.3 Syntax errors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
5.7 Tracing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
5.7.1 IBM Informix JDBC Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
5.7.2 IBM Data Server Driver for JDBC . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Chapter 6. IBM Informix with Hibernate . . . . . . . . . . . . . . . . . . . . . . . . . . 189
6.1 Hibernate for Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
6.1.1 Overview of Hibernate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
6.1.2 Hibernate concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
6.2 Setup and configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
6.2.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
6.2.2 Configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
6.3 Using Hibernate with an Inform