It would be great if iSeries programmers knew how to use Java to create e-business applications, but programmers can still forge ahead if they aren't trained in Java yet. WebSphere tools make it easy, and Jim Mason and Dave Slater show you just how easy it can be.
IBM e-business tools at a glance
IBM knows most iSeries customers can't wait for the existing developers to be retrained in Java before delivering e-business applications. As a result, the IBM Toronto lab has focused on delivering integrated toolsets that are easier to use than those found on other IBM platforms.
IBM Toronto has delivered some tools that allow you to build SIMPLE Java Web database applications without knowing Java. A great concept. The payoffs are the following:
- You can build a Java Web application accessing your database the first day you work with the tools.
- You can enhance the basic Java Web application both visually and programmatically as you develop better skills.
IBM has several versions of WebSphere Studio available for iSeries developers. The old version (WebSphere Studio) is at version 3.5x or 4.0. It contains both an SQL statement builder to create SQL statements for a database (like SELECT, INSERT, UPDATE, DELETE, etc.) and a database Web application wizard to use the SQL statement and generate a Java Web database application.
IBM is updating its development toolsets to new versions based on the open-source integrated development environment (IDE), Eclipse. One version you can download for free and test with today is the trial version of WebSphere Studio Application Developer (WSAD) or WebSphere Studio Site Developer (WSSD) for Windows or Linux. IBM Toronto will be releasing a new iSeries-specific Studio toolset later this year that includes most of these features and many new ones for the iSeries as well. All of the IBM development tools for the iSeries versions are contained in product 5722-WDS, which is a no-charge upgrade for customers on software subscription for one of the existing older development tools (like SEU or RPG).
Use the Java Skills pyramid to learn and use the new tools
Our Java Skills Pyramid has four primary skill levels for Java development:
1. Application generation:
Here, developers answer a few questions for an application wizard that will generate the Java application for you. The generated application has source that can be maintained and enhanced.
2. Visual programming:
At this level, developers design and develop Java applications using visual tools that maintain or generate Java code. Examples include the PageDesigner tool in WebSphere Studio for building HTML and JSP pages.
3. Object-based application scripting:
At this level, developers write application logic using the Java language. In many cases, the application framework may have been generated by tools, but the business logic is added by writing Java code much the same as RPG developers code logic in subroutines or procedures. This is VERY similar to writing a Visual Basic application, but Java is easier to learn for scripting. Like VB, you use components or controls to reduce the amount of code you need to write.
4. Object-oriented component development:
At this level, developers are designing and building reusable Java beans as components that dramatically cut the cost of development. This is very different than traditional RPG application development that doesn't support a component model. It's also different than traditional object-based scripting like VB because you can create or extend anything almost in the development or runtime environment.
The skill sets and time to master each of these levels varies dramatically. With good training and effort, RPG developers can very quickly master visual programming in Java. Level 2, application scripting business logic in Java takes longer (three weeks to three months). Level 3, component development usually takes significantly longer and requires the development of OO design skills. Time to learn those skills depends on the developer's background coming in.
Design for a simple Java Web database application using Web wizards
In the example below, we show how easy it is to build a Java Web database application using the wizards in the trial version of WSAD. The older version of WebSphere Studio for iSeries has a similar tool to build the same type of application. If you are using that tool, though, the actual panel details vary slightly.
Install the WSAD tool on a PC that has preferably 512M bytes of memory and several gigabytes of disk space available.
The simple application flow is appropriate for any application that has to perform table selection and detail view (like MANY RPG subfile programs do). The basic workflow for a user:
- Enter selection criteria on an input form, press submit.
- A Master View (similar to a subfile) is produced, showing all the detail records found.
- Select a row in the Master view (like selecting a subfile row), press submit.
- A Details View for that specific record is shown.
Buttons are included that allow navigation forward and backward through the application. The application will include HTML pages, Java Server Pages (JSPs), Java servlets and Java beans.
Later, you can use this basic application and enhance it to allow update, etc. for the details view and so on.
Prerequisites for building the sample application
1. Install the trial version of WSAD from the URL above.
2. Have access to an AS/400 with DB2 and the Java toolkit jar (JT400.jar) or use DB2 UDB for Windows or Linux
Seven steps to build the Java Web database app using Web wizards
Our application example uses the EMPLOYEE table that is distributed with DB2 UDB for Windows or Linux in the SAMPLE database. You can substitute any table on your AS/400 IF you have the Java toolkit driver available (JT400.jar file).
If you have questions during the exercise, in WSAD, to get help on any field on any panel, press F1 and either a dialog opens with the field help or the help perspective opens for the panel.
Each step usually begins from the WSAD workbench and either creates a new object of a given type (e.g., a project) or uses an object and then the workbench menus to perform a series of actions.
1. Create a variable to refer to your Java database driver
Add an environment variable to hold your database driver classes in the Workbench. For a DB2 UDB connection in Windows, Linux etc, the driver zip file is db2java.zip. For a remote AS/400 connection, the driver file is JT400.jar.
-- Window, then preferences, then Java, then Classpath variables.
-- Select NEW to create a new classpath variable.
-- Enter a name. (In this case, use DB2JAVA. For AS/400, use JT400.)
-- Browse to select a file (here c:sqllibjavadb2java.zip. For remote AS/400: in &amp;#91; wsdi install dir &amp;#93;javajt400.jar).
-- Press OK. The variable is now available to add to any project's build path. The build path defines all the folders, files used in the project's classpath when classes are compiled.
2. Create a database project to hold database information
In data perspective, create a new java project (we used cx21db1).
3. Import database information
In the data perspective, select the data explorer tab in the left pane. Then, right button menu to select "create new connection".
Set connection information:
-- connection name (here db2_sample)
-- database name (here SAMPLE)
-- user id
-- database type (here DB2 UDB v7.2)
-- JDBC driver type (here IBM DB2 app driver for Windows)
-- host name (For AS/400, specify the AS/400 system name)
-- port (For AS/400, default port is 8475).
-- JDBC driver name (here COM.ibm.db2.jdbc.app.DB2Driver. For AS/400, com.ibm.as400.access.AS400JDBCDriver).
-- Class location (here C:sqllibjavadb2java.zip. For AS/400, jt400.zip).
-- Connection URL (calculated from the above info).
Click Finish. The database connection is created for the database and the database meta data is imported.
Select import to folder
-- From the database project, select the database connection.
-- Select import.
-- The database metadata is imported into the database project folder.
The database definitions are stored as xmi documents. That allows the development tools to use database informationfor building statements, applications etc OFFLINE for the first time.
4. Create an SQL statement with SQL wizard
Create new SQL statement.
For statement info page 1
-- SELECT statement type
* Option to be guided through statement creation.
* Use existing database model, select SAMPLE from the dropdown list in cx21db1.
* Give the statement a name: empqxLastName1.
-- Select the table (EMPLOYEE).
-- Select the columns (LASTNAME, FIRSTNME, WORKDEPT, PHONE, EMPNO).
-- Create a WHERE clause to select records (WHERE LASTNAME >= :LASTNAME).
* Select a column (LASTNAME).
* Select an operator (>=).
* Select a value (Build expression, then set a host variable name -- we used lastname).
-- Select a column for an ORDER BY clause (LASTNAME).
-- On the review page, run the statement to verify it works correctly.
* Substitute a value for the starting last name (e.g., 'D').
* A table of names should be returned.
-- Select Finish to save the statement.
5. Create a Web project
Create a Web project for the database Web application.
Enter project info
-- Project name ( cx22Web1 )
-- If desired, select option to create CSS file (cascading style sheet). (If you have a style sheet, skip this option and copy your existing one later.)
-- Leave the default enterprise application project name (DefaultEAR).
-- If adding other jars for your application, press next and add them.
-- Press next, on the Build path page, add the classpath variable for your database driver (here DB2JAVA, for your remote AS/400: JT400).
6. Create a Web application with database application wizard
Create the database Web pages using your Web project and SQL statement.
From the Web project, select New Web, then database Web pages.
Enter the create page info:
-- The folder is the WebApplication folder under your Web project (here cx22Web1).
-- Leave the options for create input form, create detail form selected.
-- Leave the View Bean model. (Optionally you could specify a custom JSP tag lib here.)
-- Leave store results in request. (Optionally you can save JDBC result set in your session.)
Select the SQL statement on the next page:
-- Your database project is shown, navigate the tree and select your SQL statement. (Here empqxLastName1)
-- Specify Runtime database connection information. (Here use the default connection info you already provided.) Optionally, you can specify a data source name if you created one.
-- Press Finish.
The Web application is generated.
7. Run on server to generate, publish, run WebSphere test server
Create a test WebSphere application server, publish your application and run it on the server.
-- In your Web application, find and select the input form. (Here EMPInputForm.html)
-- Right button menu, select "Run on server".
The test WebSphere application server configuration and instance is created in the workbench. The test WebSphere server is started. The application is published. Your input form is invoked in a test browser.
Input your starting name and run the application. (And how much Java did you need to know to do this?)
About the authors: Jim Mason is president of ebt-now.com, and he writes, consults, teaches, designs and develops iSeries Web applications using Java, WebSphere, DB2, Lotus Domino and the WebSphere Development Tools for AS/400. Dave Slater is World Wide Market Manager of AS/400 Application Development at IBM Canada.