IBM ® WebSphere® Application Server Version 5.0 (hereafter called Application Server) comes with a set of samples that demonstrate the Application Server's robust functionality. The samples come complete with source code so that you can use them to learn how to implement Web technologies, such as servlets, Java Server Pages (JSP), and Enterprise Java Beans (EJB). Among these, the Plants by WebSphere sample is a complete Web application that accesses information stored in a database. To make it easy for you to get started, this sample runs "out of the box" on a Cloudscape database. In a real-world environment, a production-level database, such as IBM DB2®, is necessary.
This article walks you through the steps to configure the Plants by WebSphere sample, shown in Figure 1, to run with the IBM DB2 database. It explains how to set up the necessary database in DB2, how to populate this database with the pictures and data for the Plants by WebSphere store, and how to configure resources in the Application Server for communication with DB2.
Figure 1. Plants by WebSphere splash page

To complete the instructions, you need the following environment:
- Windows® 2000 + Service Pack 3
- DB2 UDB 7.2 + FixPak 7 or DB2 UDB 8.1 + FixPak 1
- WebSphere Application Server Version 5
You will also need to download and unzip the plantsbyDB2.zip file.
This zip file contains:
- Batch files to create the PLANTSBY database in DB2
- Java class file to populate the database
- Java Command Language (JACL) script file to create and configure the resources for DB2 on the Application Server configuration files
Creating and populating the PLANTSBY database in DB2
Before proceeding, verify that you can execute java.exe and db2cmd.exe from the command prompt. If you cannot execute these files, locate them on your machine and add the file paths to your system path.
To create and populate the PLANTSBY database in DB2:
- Locate the batch file,
db2createplantsby_db.bat, in theinstallsubdirectory created after unzipping theplantsbyDB2.zipfile. Enter the following at a command promptdb2createplantsby_db [db2admin] [pw], where db2admin is your DB2 user ID and pw is your DB2 password.This batch file connects to DB2 using the Java Database Connectivity (JDBC) API and creates the PLANTSBY database. To see the commands that are called, view the db2creatplantsby_db.bat file with a text editor.
- Locate the Plants by WebSphere image files in the following
directory:
install_root\samples\src\PlantsByWebSphere\PlantsByWebSphereWAR\images\archive
where:
install_rootis the location of your Application Server (ex.C:\WebSphere\AppServer)
Copy all of the images into theinstallsubdirectory that you created after unzipping theplantsbyDB2.zipfile. Make sure that the images are in the same folder as thePopulate.classfile so that it can access these images and insert them into the PLANTSBY DB2 database.
- Locate the Java class file,
Populate.class, in theinstallsubdirectory. Add the current directory and the path of thedb2java.zipfile (typicalyDB2_install_root\SQLLIB\java12\) to your CLASSPATH.
- To populate the PLANTSBY tables, enter the following at a command
prompt:
java Populate [db2admin] [pw], where db2admin is your DB2 user ID and pw is your DB2 password.This file connects to the PLANTSBY database using the JDBC API and creates the following tables:
- CUSTOMER
- INVENTORY
- ORDERINFO
- ORDERITEMS
The file then inserts all of the data for each item into the INVENTORY table, including the image files. You can view the Populate.java source file located in the install subdirectory for details.
Uninstalling, rebuilding and reinstalling the Plants by WebSphere enterprise archive file
The Plants by WebSphere sample contains Cloudscape deployment code, so you must reinstall a clean enterprise archive (EAR) file without deployment code specifying that you are running the sample with DB2. These next steps explain how to uninstall the Plants by WebSphere EAR file, build a clean EAR file without deployment code, and reinstall the EAR file with DB2-specific deployment code. The Application Server handles the creation of DB2 deployment code.
Executing the Plants by WebSphere sample build script
To rebuild the Plants by WebSphere sample:
- Add
install_root\binto your PATH. - Change to the
install_root\samples\src\PlantsByWebSpheredirectory and enter the following at a command prompt:
buildsamples
The batch file, buildsamples.bat,
is located in the install_root\bin directory.
The script sets the appropriate class path information and executes
the Ant 1.4 build utility. The Ant utility reads the build.xml
files, which describe how to build the sample. Refer to the
Jakarta Web site for additional documentation on Ant 1.4. The
new, clean EAR file is located in the install_root\samples\lib\PlantsByWebSphere
directory.
Removing and reinstalling the PlantsByWebSphere.ear file
By default, the Plants by WebSphere sample is
installed in the install_root\installedApps\<cell
name> directory, where <cell name>
is the name of the cell where your application is installed.
To reinstall the sample:
- Stop the Application Server.
- Remove the Plants by WebSphere sample EAR file (
install_root\binmust be in your PATH) by entering the following at a command prompt:wsadmin -conntype none -c "$AdminApp uninstall PlantsByWebSphere"
- Change to the
install_root\samples\lib\PlantsByWebSpheredirectory. - Reinstall the Plants by WebSphere sample EAR file with DB2-specific
deploy code by entering the following:
wsadmin -conntype none -c "$AdminApp install PlantsByWebSphere.ear {-appname PlantsByWebSphere -usedefaultbindings -node [node] -deployejb -deployejb.dbtype DB2UDB_V72 -server [server]}"
where:
nodeis the name of the node on which to install the sample
serveris the name of the server on which to install the sample
The Plants by WebSphere EAR file is now redeployed to the Application Server with DB2-specific deployment code. Restart the Application Server and configure resources before running the sample.
Configuring DB2 resources for the Application Server
Now that the PLANTSBY database exists and the
EAR file is redeployed, you must configure the database resources
on the Application Server. For this step, you can either execute
the provide JACL script, pbwconfigDB2.jacl, or you
can manually set up the resources through the administrative console
of the Application Server. Instructions for both procedures are
provided.
Configuring resources using the Java Command Language script
To automate the configuration of resources for
DB2, run the Java Command Language (JACL) script provided in the
plantsbyDB2.zip file:
- Locate the JACL file,
pbwConfigDB2.jacl, in theinstallsubdirectorytha was created after unzipping theplantsbyDB2.zipfile.
- Enter the following at a command prompt:
wsadmin -conntype none -f pbwConfigDB2.jacl [node] [DB2 driver class path] [DB2 ID] [DB2 pw]
where:
nodeis the name of the node on which to install the sample
DB2 driver class pathis the location of thedb2java.zipfile, typicalyDB2_install_root\SQLLIB\java12\db2java.zip
DB2 ID/pware the values for your DB2 user ID and password
Important: Enclose the DB2 driver class path in brackets and quotation marks.
For example,{"C:\Program Files\SQLLIB\java12\db2java.zip"}
The JACL script creates and configures all the necessary resources using wsadmin scripting commands. At this point, you are ready to run the Plants by WebSphere sample.
The next section illustrates how to configure the resources through the administrative console rather than through the automated JACL script
Configuring Resources using the administrative console
To configure resources through the administrative console, complete the following steps:
Create a new DB2 JDBC Provider
- Start the Application Server.
- Launch the administrative console by typing
http://localhost:9090/admin. You might have to changelocalhostto the machine name where WebSphere Application Server is installed. For example,http://<hostname>:9090/admin. - Click Resources > JDBC Providers.
- Select the radio button for Server Level Scope and click Apply.
- Click New.
- Select DB2 JDBC Provider from the list and click OK.
See Figure 2.
Figure 2. JDBC Providers page
- On the General Properties panel, indicate the class path for
the
db2java.zipfile (usuallyDB2_install_root\SQLLIB\java12\db2java.zip). See Figure 3.
Figure 3. JDBC provider properties
- Click OK.
Create a new DB2 data source
- Click Resources > JDBC Providers.
- Click the new DB2 provider you just created.
- Scroll down and click Data Sources under Additional Properties.
- Click New.
- Name the data source,
pbwdatasource. - Change the Java Directory Naming Interface (JNDI) name to
jdbc/PlantsByWebSphereDataSource. - Select the check box for Container managed persistence.
- Verify that the data in your panel matches Figure 4.
Figure 4. Data source properties
- Click OK.
Configure your new DB2 data source
- Click on the data source you just created, then scroll down and click Custom Properties.
- Click databaseName.
- In the databaseName field, type
PLANTSBYfor the value and click OK. See Figure 5.
Figure 5. Database name
- From the Resources > JDBC Providers > DB2 JDBC Provider > Data Sources > pbwdatasource page, scroll down and click J2C Authentication Data Entries under Related Items.
- Click New.
- Make an alias (any unique name). Change your user ID and password to match your DB2 user ID and password.
- Click Resources > JDBC Providers > DB2 JDBC Provider > Data Sources > pbwdatasource.
- Select the new alias you just created for Component-managed Authentication Alias.
- Repeat this step for Container-managed Authentication Alias.
Your results will look similar to Figure 6.
Figure 6. Authenication aliases
- Click OK.
Change the PlantsByWebSphere data source JNDI name
- Click Resources > JDBC Providers > Samples Cloudscape 5.0 Provider > Data Sources > PLANTSDB.
- Change the JDNI name to
jdbc/PlantsByWebSphereDataSource_cloud(this action avoids naming confusion with the new DB2 data source). - Click OK.
- Click Save near the top of your panel.
- Click Save on the Save to Master Configuration
panel.
Whether you configured the Application Server resources through the administrative console or through the provided JACL script, you are now ready to run the Plants by WebSphere sample. All data retrieval and storage now runs through the DB2 database, PLANTSBY.
This article explains the necessary steps to configure the Plants by WebSphere sample to run on the Application Server using DB2 instead of Cloudscape. Following this process, you can configure other applications to utilize DB2, configuring their resources in the same way that you configured resources for Plants by WebSphere. Remember that enterprise beans using bean-managed persistence contain database-specific code that might require modification to run on DB2 or any other relational database.
| Name | Size | Download method |
|---|---|---|
| plantsbyDB2.zip | 23 KB | FTP |
Information about download methods

Tom Krieger is a software engineer at the IBM Lab in Research Triangle Park, North Carolina. Tom is a co-op currently working towards his undergraduate degree in Computer Science at Virginia Tech. You can reach Tom at tckriege@us.ibm.com .




