Still a work in progress, ArdGate allows users to insert, update, and delete data with interactive SQL, QMQRY, and embedded SQL.
If you want to access data in the DB2 for i database from a remote computer, it's not that difficult. However, if you are working on an iSeries and you wish to connect to a remote database server to manipulate data, it can be a bit of a challenge.
"Using ODBC, you can connect from another system to the AS/400 but not in the opposite direction," says Dieter Bender, an independent RPG programmer in Wettenberg, Germany. Bender has been active in the MC Press RPG Forums lately sparring with author Tom Snyder (Advanced Integrated RPG) over various approaches to utilizing Java in RPG programs. Both are RPG programmers who work on the iSeries and who have become expert in utilizing Java to perform certain jobs that are cumbersome using RPG.
Bender has developed and released to open source a database driver for DB2 that he says IBM should have introduced ages ago. "If IBM would have announced universal database connectivity with IBM i 7.1 from DB2 for i to all databases on the market through Add RDB Directory Entry (ADDRDBDIRE PORT [*JDBC]), this would have been the top announcement," Bender says.
"It's no problem talking to another database from an AS/400 Java program," says Bender. "But from the most-used languages—like RPG and COBOL—it's not possible to talk with a remote database using SQL. It's not offered by IBM; they don't have this on i," he says. Using RPG or COBOL, besides DB2, only Oracle can be accessed by normal SQL using Oracle Access Manager.
Bender says he came up with the idea to address this deficiency while programming at a business client, but he knew that if he created a unique driver while under contract, his employer would likely lay claim to the copyright. "If I'm working as a consultant for a large company, normally they try to get the copyright on everything that I write," he says. So Bender released his driver into open source. He still introduces it to companies where he works doing customizations, but they can't hang onto it and prevent its use elsewhere.
ArdGate, Bender's open-source solution, closes the gap and makes all databases on the market available for normal SQL access, regardless of whether it's done by interactive SQL, QMQRY, or embedded SQL, says Bender. ArdGate, which you can find nested in the download from the link above and which Bender says is still a "work in progress," is mostly written in Java but has a small RPG interface layer that serves as a connector to the SQL client integration exit. It is based on (and uses) Bender's "high performance" RPG-to-Java engine, AppServer4RPG. Bender says that the engine uses one pre-started Java Virtual Machine (JVM) to serve multiple clients in a multithreaded environment. He says the engine supports highly scalable usage and fast response times.
Figure 1: The ArdGate architecture shows connections with the remote DB. (Click images to enlarge.)
Enabling connections to a remote database is done in the normal way and begins by adding an entry to the remote database directory, says Bender. With the entry, the connector JVAGATE is registered as *ARDPGM and all SQL statements regarding this remote database are routed by DB2 to the exit program. Most of the work is done by the Java portion of the application. To complete the registration, two lines must be added to the configuration of ArdGate, specifying how to access the database and listing the name of the JDBC driver.
Figure 2: Enabling connections to a remote database is done in the normal way and begins by adding an entry to the remote database directory.
Installation is simplified by providing the RPG part ready for use as savefile and repackaging the Java part as a Web archive for easy deployment to a Web container such as WebSphere or Tomcat. It can be installed as a standalone Java application, but that entails adjusting classpath settings to add additional JDBC drivers. Once installed, you can connect to the database by its name in the remote database directory. Multiple connections are possible to different databases within the same activation group or to the same database in different activation groups. ArdGate serves multiple connections from different jobs at the same time by multithreading, Bender says.
Figure 3: Above is an example program to access a remote database using ArdGate.
The current release (Milestone 3) of ArdGate has the following features:
- Select, insert, update, delete with interactive SQL
- Field selection with F4 from STRSQL
- INTEGER, DECIMAL, NUMERIC, CHAR, VARCHAR, DATA, TIME, TIMESTAMP data types as provided by the target database
- Support for null values and null indicators in embedded SQL
- Insert with host variables
- Searched update and delete with host variables
- Cursor definition with prepare and host variables
- Fetch single line (no scrollable cursor)
Bender says Milestone 4 should contain declare cursor, select into, positioned update, positioned delete, and procedure call. For Milestone 5, support for commitment control is planned, he says.
"The original project is nearly two years old," says Bender. "The first part was to build a mechanism to make calling Java routines from RPG without having a Java Virtual Machine in every job," he says. After trying a workaround using Apache Derby, an open-source relational database implemented in Java, Bender decided upon the SQL client integration exit point from the AS/400. Talking with the remote database is done by Bender's Java application. The other part, which is tied to the database name in the remote database directory, sends DB2 data to the Java application via the client integration exit, and the Java application talks with the remote database. The result, says Bender, is you can file SQL statements as you would with a local database.
as/400, os/400, iseries, system i, i5/os, ibm i, power systems, 6.1, 7.1,