Welcome!

ColdFusion Authors: Yakov Fain, Maureen O'Gara, Nancy Y. Nee, Tad Anderson, Daniel Kaar

Related Topics: ColdFusion

ColdFusion: Article

Macromedia ColdFusion - MX to iSeries Demystified

A world-class database platform paired up with a world-class Web application server

In this article, I'll show you how to connect ColdFusion MX to an IBM iSeries (formerly AS/400) DB2 database. I'll describe your connectivity options and give you configuration examples.

While attending an iSeries conference a couple of years ago, I had the opportunity to talk with an IBM DB2 engineer. I still remember the blank look on his face when I explained that I use ColdFusion to access his database. In his defense, I've enlightened more than a few Macromedians as to what an iSeries is and what it does. Thank heaven for standards and thank the heavens again for Macromedia's and IBM's adherence to them.

There are several ways to get to DB2 data on the iSeries. We'll concentrate on ODBC and JDBC. Platform examples will include ColdFusion MX 6.1 on Windows 2000 Server and JRun/ColdFusion MX 6.1 on Apple OSX 10.1.5.

Windows 2000 Server
ODBC Configuration Step by Step Installation

To make ODBC work, you need Client Access for iSeries installed on the ColdFusion Server. Client Access for iSeries is a licensed program and is available on the media distributed with the operating system. ODBC is an option provided with the Client Access tools suite. For security reasons it's best to perform a selective setup and choose only the options you will need (see Figure 1).

 

In the iSeries world, a software patch is known as a PTF or Program Temporary Fix. I cannot stress enough how important these are. Make sure that you download and apply the latest iSeries Client Access PTFs.

Creating a System DSN for ODBC
Create a system DSN with the Windows ODBC Administrator using the iSeries Access ODBC driver. I won't cover all the settings, but I'll point out a few that will make it work better with MX Studio and Server.

Server Tab
Naming convention differences: It's best to use SQL naming instead of system or *SYS. SQL naming uses dotted notation when separating libraries and files. *SYS uses the less-common forward slash mark.

Library list: This is where you set the libraries that this ODBC connection will use to find data. While explicit paths will work in your SQL statements, the libraries will not show up in the Studio MX available libraries list for the data source.

Performance Tab
Use blocking with fetch of one row: Use this option when your application iterates through small blocks of sequential records.

Enable lazy close support: This option prevents unnecessary opening and closing of connections.

Create a ColdFusion Data Source
Open your ColdFusion server administration screen and create a new data source. The type will be ODBC Socket and the name will be the name you gave to the System DSN. Supply a profile and password, verify the data source, and you should be ready to go.

Diagnostics/Troubleshooting
This is where ODBC has bragging rights over JDBC on the iSeries. The ODBC facilities for troubleshooting application performance and connectivity are as comprehensive as they are easy to use. You can access these tools from the Windows 2000 ODBC configuration panel.

Windows 2000 Server
JDBC Configuration Step by Step

IBM provides three JDBC drivers for the iSeries: the Native JDBC driver, the JT400 or IBM Java Toolbox driver, and JTOpen, the open source driver. The native driver, while faster than the others, will only run on the iSeries JVM.

What is the IBM Toolbox for Java? What is JTOpen? What are the differences? The answer is very little. The IBM Toolbox for Java is the polished, refined older brother of JTOpen.

JTOpen is the bleeding-edge open source version of the toolbox. It includes contributions from the open source community along with the newest fixes and enhancements from IBM. JTOpen is covered by the IBM Public License. Perhaps the most significant difference between the two is how the products are supported. JTOpen's support is provided through an online forum whereas the Toolbox is supported through traditional IBM software support channels.

The Toolbox formally known as the "IBM Toolbox for Java" is the licensed version of JTOpen. It's shipped with the iSeries as part of the base operating system and can be referenced by its licensed program code 5722JC1 or 5769JC1 for OS/400 versions prior to V5R1.

IBM Toolbox for Java and JTOpen Installation

  • See www-1.ibm.com/servers/eserver/ iseries/toolbox/faq.htm#faqG and http://publib.boulder.ibm.com/iseries/v5r1/ic2924/ index.htm?info/rzahh/rzahnm04.htm for system requirements.
  • Use iSeries Operations Navigator to locate the Java Toolkit folder on the iSeries. You can find it in the QIBM/ProdData/HTTP/Public/jt400/ IFS folder. If it's not installed, have your system administrator install the licensed program 5722JC1 (V5Rx) or 5769JC1 (V4Rx).

    or

  • Download the latest JTOpen from www-1.ibm.com/servers/eserver/iseries/toolbox/downloads.htm.
  • Create a folder on your ColdFusion MX Server. To minimize the classpath length I put one in the root and called it C:JT400 or C:JTOpen.
  • Copy the contents of QIBM/ProdData/HTTP/Public/jt400/ or extract the JTOpen zip file into your new folder.
  • Using the ColdFusion administrator, navigate to Java and JVM Settings and put C:/JT400/lib/jt400.jar or C:/JTOpen/lib/ jt400.jar into the classpath box. If you have multiple classpaths, separate them with a comma (see Figure 2).

  • Stop and restart the ColdFusion MX Application Server service.
  • Under "Data & Services" on the left navigation bar, click Data Sources. In the "Add Data Source" area, give your data source a name, then choose the other driver type and click Add (see Figure 3).

     

  • CF Data Source Name = My_iSeries
  • JDBC URL = as jdbc:as400://[iSeries server name or address]/[Database Name];prompt=false; You can verify the name by entering the WRKRDBDIRE command on the iSeries. Don't forget the prompt=false. This prevents the iSeries from sending a profile/password dialog box to the ColdFusion server in the event of an invalid profile/password. Without it, the ColdFusion server could hang.
  • Driver Class = com.ibm.as400.access.AS400JDBCDriver
  • Driver Name = Optional
  • Username = Optional. You can always append this information later in your application. I use a username and password during setup and remove it when I know it works.
  • Password=Optional
  • Description=Optional

    ColdFusion is now connected to the iSeries (see Figure 4).

     

    Apple OSX
    JDBC Configuration Step by Step

    The most intriguing capability for Web developers may be OS X's built-in support for Java. OS X ships with Java2 Standard Edition (J2SE), allowing developers a native environment to deploy their Java applications.

    Connecting to the AS400 from JRun and ColdFusion

  • Open the JRun Management Console (JMC) from your browser. Click on the default server link in the "Welcome to Macromedia JRun 4" window.
  • Add a classpath to the JTOpen.jar file you installed into the root level of the hard drive. Click on Settings, then JVM Settings. In the Java VM Settings window, go to the Classpaths for Java VM area, and click the Browse button next to the New Classpath text field. Navigate to the /JTOpen4/lib/jt400.jar file and click Open. The classpath will appear in the "New Classpath" text field. Click Add, then Update at the bottom of the window.
  • Open the ColdFusion MX Administrator.
  • Under Data & Services on the left navigation bar, click Data Sources. In the Add Data Source area, give your data source a name, then choose the other driver type and click Add.
  • In the Add window, enter the JDBC URL as jdbc:as400://[iSeries server name or address]/[Database Name];prompt=false
  • The Driver Class is com.ibm.as400.access.AS400JDBCDriver. The Driver Name field is optional. Enter your AS400 username and password, and a brief description of the data source. Click Submit. You can verify that the data source is connected to the database in the Data Sources window by clicking the checkmark icon next to the data source name.
  • ColdFusion is now connected to the AS400.

    Performance Tips & Additional Settings
    Now that you have a basic connection to the iSeries, it's time to do some performance tuning. While researching this article I performed countless query tests against various driver and server settings. I quickly realized that comprehensive performance tuning was well beyond the scope of this article. I've included links to IBM documentation at the end of the article.

  • Avoid using "Select *": ODBC and JDBC will perform unnecessary field-level processing if you use only a few fields.
  • Use connection pooling: The instantiation of a new connection will result in a noticeable performance hit even on the fastest of systems. New connections to a fast iSeries took an average of 350ms to establish without connection pooling turned on.
  • Install the latest patches from IBM and Macromedia: Not only do they fix problems, they add functionality and performance. Both companies have a good track record when it comes to fixes.
  • Take advantage of DB2's stored procedures: You can call them directly from SQL.

    <cfquery name="myQuery" datasource="my_iSeries">
    { library.program('parm') }
    </cfquery>

    I'm not a DBA and I don't know all that much about packaging in DB2, but if you do and want to use it here's how to set it up:

    jdbc:as400://[iSeries server name or address]/[Database
    Name];prompt=false;libraries=*libl,mylib;extended dynamic=true;
    package=mypackage;package library=mylib;package cache=true;

    Modifying the block size and enabling data compression may also improve performance depending on your workload.

    as jdbc:as400://[iSeries server name or address]/[Database
    Name];prompt=false;libraries=*libl,mylib;block size=512;
    data compression=true;

    Conclusion
    The Java Toolkit comes with literally hundreds of Java classes that you can access using the <cfobject> tag. The simple call in Listing 1 gets disk space information.

    What a combination! A world-class database platform paired up with a world-class Web application server. Thanks to standards, ODBC and JDBC are just the tip of the iceberg when it comes to integrating ColdFusion with the iSeries.

    Acknowledgment
    I'd like to thank my coworker and Apple guru Robert Haddan. He configured, tested, and documented the configuration process on OS X.

    Additional iSeries Resources

  • Troubleshooting ODBC: http://publib.boulder.ibm.com/iseries/v5r2/ic2924/ index.htm?info/rzaii/rzaiiodbc22.HTM
  • Performance Tuning ODBC: http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/ rzaik/rzaikodbcperfconsd.htm
  • JDBC Properties: http://publib.boulder.ibm.com/iseries/v5r2/ic2924/ index.htm?info/rzahh/javadoc/JDBCProperties.html
  • Troubleshooting JDBC: www-1.ibm.com/servers/eserver/iseries/toolbox/ troubleshooting.htm#RecordLevelAccess
  • Performance Tuning JDBC: http://publib.boulder.ibm.com/iseries/v5r2/ic2924/ info/rzaha/jdbcperf.htm
  • More Stories By Jeremy Lyon Lyon

    Jeremy Lyon is the eGovernment Coordinator for the Oregon Department of Revenue. Jeremy has over 15 years of administration and programming experience utilizing systems ranging from the Timex Sinclair 1000 to the Cray XMP supercomputer.

    Comments (14)

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.