# Configure PlantsByWebSphere with DB2

This document provides instructions for configuring PlantsByWebSphere to run with DB2.

To complete these instructions, you will need the following:

- DB2 UDB Enterprise Edition 7.2 Fixpack 7
- Websphere Application Server 5.0
- The PlantsByWebSphere sample that comes installed with the Application Server

### I. Create and populate the PLANTSBY database in DB2

1. Ensure that Java\bin and SQLLIB\bin are in your path so that you can run the java.exe and db2cmd.exe commands.
2. Run the batch file db2createplantsby_db.bat (located in the install folder one directory down) to create the PLANTSBY database. Enter your DB2 user id and password as command line parameters.
3. Run the java class file Populate.class to populate the PLANTSBY tables. Enter your DB2 user id and password as command line parameters.

### II. Reinstall a clean PlantsByWebSphere EAR

The PlantsByWebSphere EAR that ships with WebSphere Application Server 5.0 comes preconfigured with Cloudscape deploy code. In order to run the application on DB2, it is necessary to build a clean ear and to generate DB2 deploy code. The following steps will guide you through this process.

1. While the server is running, open the Samples Gallery, then click on PlantsByWebSphere => Build it Yourself.
2. Follow the instructions to rebuild, remove and reinstall the PlantsByWebSphere.ear file with one change:

- In step 3 under Removing and reinstalling the PlantsByWebSphere.ear file use the following wsadmin command:

    install_root/bin/wsadmin -conntype none -c "$AdminApp install PlantsByWebSphere.ear {-appname PlantsByWebSphere -usedefaultbindings -node <node>; deployejb -deployejb.dbtype DB2UDB_V72}"

    where <node> is the name of node on which to install the Sample.

This deploys the PlantsByWebSphere EJBs with DB2-specific deploy code

### III. Create a new DB2 JDBC Provider

1. Open up the admin console while your server is running (http://localhost:9090/admin)
2. Click on Resources => JDBC Providers => Server and click Apply. Then click New. See figure 1.

| Figure 1.

3. Select DB2 JDBC Provider from the drop down box and click Ok. See Figure 2.

| Figure 2.

4. Change the classpath in the next screen to point to db2java.zip (usually in DB2INSTALL\SQLLIB\java12\)

| Figure 3.

5. Click Ok.

### IV. Create a new DB2 datasource

1. On the JDBC providers page click on the new DB2 provider you just created.
2. Scroll down and click on Data Sources under Additional Properties. See Figure 4.

| Figure 4.

3. Click new.
4. Give the datasource a name (any unique name). Then change the JDNI name to jdbc/PlantsByWebSphereDataSource. Check the Use CMP checkbox. Check that your screen is the same as Figure 5.

| Figure 5.

5. Click Ok.

### V. Configure your new DB2 datasource

1. Click on the datasource you just created then scroll down and click on Custom Properties.
2. Click on databaseName
3. In the database name field, type in PLANTSBY for the value and click Ok. See Figure 6.

| Figure 6.

4. Click back to the pbwdatasource view (link at top of screen),then scroll down and click on J2C Authentication Data Entries under Related Items.
5. Click on New.
6. Make an alias (any unique name). Change your user id and password to match your DB2 user id and password. See Figure 7.

| Figure 7.

7. Click Ok.
8. Go back to the pbwdatasource view and scroll down to Component-managed Authentication Alias.
9. From the drop down menu, select the new alias you just created.
10. Repeat this step for Container-managed Authentication Alias. Your screen should look similar to Figure 8.

| Figure 8.

11. Click Ok.

### VI. Change the PlantsByWebSphere Data Source

1. Click back to the JDBC Providers page under Resources. Then click Samples Cloudscape 5.0 Provider => Data Sources => PLANTSDB
2. Change the JDNI name to jdbc/PlantsByWebSphereDataSource_cloud (this avoids naming confusion with the new DB2 data source).
3. Click Ok.
4. Save changes to master configuration.

### Congratulations! You have successfully configured PlantsByWebSphere to run using DB2. Stop the server if it is running, then restart and open the PlantsByWebSphere sample from the gallery. All the data is now being stored and accessed on the DB2 PLANTSBY database.