How to Run WebSphere Application Server Version 5 Samples on DB2

This article walks you through the steps to configure the Plants by WebSphere sample (from the Sample Gallery in WebSphere Application Server V5) to run with an IBM DB2 database. It explains how to set up the DB2 database, populate it, and then configure the Application Server's resources to communicate with it.

Share:

Tom Krieger, WebSphere Application Server Samples, IBM Research Triangle Park

Photo: Tom KriegerTom 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 .



07 April 2003

Introduction

IBM ® WebSphere® Application Server Version V5 (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
Plants by WebSphere Splash Page

Environment

To complete the instructions, you need the following environment:

Download

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:

  1. Locate the batch file, db2createplantsby_db.bat, in the install subdirectory created after unzipping the plantsbyDB2.zip file. Enter the following at a command prompt db2createplantsby_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.

  2. Locate the Plants by WebSphere image files in the following directory:

    install_root\samples\src\PlantsByWebSphere\PlantsByWebSphereWAR\images\archive

    where:
    install_root is the location of your Application Server (ex. C:\WebSphere\AppServer)

    Copy all of the images into the install subdirectory that you created after unzipping the plantsbyDB2.zip file. Make sure that the images are in the same folder as the Populate.class file so that it can access these images and insert them into the PLANTSBY DB2 database.
  3. Locate the Java class file, Populate.class, in the install subdirectory. Add the current directory and the path of the db2java.zip file (typicaly DB2_install_root\SQLLIB\java12\) to your CLASSPATH.
  4. 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:

  1. Add install_root\bin to your PATH.
  2. Change to the install_root\samples\src\PlantsByWebSphere directory 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:

  1. Stop the Application Server.
  2. Remove the Plants by WebSphere sample EAR file (install_root\bin must be in your PATH) by entering the following at a command prompt:
       wsadmin -conntype none -c "$AdminApp uninstall PlantsByWebSphere"
  3. Change to the install_root\samples\lib\PlantsByWebSphere directory.
  4. 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:
    node is the name of the node on which to install the sample
    server is 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:

  1. Locate the JACL file, pbwConfigDB2.jacl, in the install subdirectorytha was created after unzipping the plantsbyDB2.zip file.
  2. Enter the following at a command prompt:

    wsadmin -conntype none -f pbwConfigDB2.jacl [node] [DB2 driver class path] [DB2 ID] [DB2 pw]

    where:
    node is the name of the node on which to install the sample
    DB2 driver class path is the location of the db2java.zip file, typicaly DB2_install_root\SQLLIB\java12\db2java.zip
    DB2 ID/pw are 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

  1. Start the Application Server.
  2. Launch the administrative console by typing http://localhost:9090/admin. You might have to change localhost to the machine name where WebSphere Application Server is installed. For example, http://<hostname>:9090/admin.
  3. Click Resources > JDBC Providers.
  4. Select the radio button for Server Level Scope and click Apply.
  5. Click New.
  6. Select DB2 JDBC Provider from the list and click OK. See Figure 2.
    Figure 2. JDBC Providers page
    JDBC Providers page
  7. On the General Properties panel, indicate the class path for the db2java.zip file (usually DB2_install_root\SQLLIB\java12\db2java.zip). See Figure 3.
    Figure 3. JDBC provider properties
    JDBC provider properties
  8. Click OK.

Create a new DB2 data source

  1. Click Resources > JDBC Providers.
  2. Click the new DB2 provider you just created.
  3. Scroll down and click Data Sources under Additional Properties.
  4. Click New.
  5. Name the data source, pbwdatasource.
  6. Change the Java Directory Naming Interface (JNDI) name to jdbc/PlantsByWebSphereDataSource.
  7. Select the check box for Container managed persistence.
  8. Verify that the data in your panel matches Figure 4.
    Figure 4. Data source properties
    Data source properties
  9. Click OK.

Configure your new DB2 data source

  1. Click on the data source you just created, then scroll down and click Custom Properties.
  2. Click databaseName.
  3. In the databaseName field, type PLANTSBY for the value and click OK. See Figure 5.
    Figure 5. Database name
    Database name
  4. From the Resources > JDBC Providers > DB2 JDBC Provider > Data Sources > pbwdatasource page, scroll down and click J2C Authentication Data Entries under Related Items.
  5. Click New.
  6. Make an alias (any unique name). Change your user ID and password to match your DB2 user ID and password.
  7. Click Resources > JDBC Providers > DB2 JDBC Provider > Data Sources > pbwdatasource.
  8. Select the new alias you just created for Component-managed Authentication Alias.
  9. Repeat this step for Container-managed Authentication Alias. Your results will look similar to Figure 6.
    Figure 6. Authenication aliases
    Authenication aliases
  10. Click OK.

Change the PlantsByWebSphere data source JNDI name

  1. Click Resources > JDBC Providers > Samples Cloudscape 5.0 Provider > Data Sources > PLANTSDB.
  2. Change the JDNI name to jdbc/PlantsByWebSphereDataSource_cloud (this action avoids naming confusion with the new DB2 data source).
  3. Click OK.
  4. Click Save near the top of your panel.
  5. 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.


Conclusion

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.


Download

DescriptionNameSize
Code sampleplantsbyDB2.zip  ( HTTP | FTP )23 KB

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into WebSphere on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere, Information Management
ArticleID=14209
ArticleTitle=How to Run WebSphere Application Server Version 5 Samples on DB2
publish-date=04072003