Chapter 4. Database 89
For stand-alone demonstrations, we implement a method to insert local pictures
into the database and another method to reset the database for the next demo.
4.4.2 Configuring a development system for DB2e and DB2e Sync
In this section, we describe the steps to configure a window development system
for DB2e and DB2e Sync.
Before you begin
Before your DB2e application can run in the development environment and find
the native DB2e drivers, some configuration is necessary.
1. For local DB2e database access, add the DB2e drivers to your system path.
They can be found in the directory:
C:\Program Files\IBM\DeviceDeveloper\wsdd\wsdd5.0\technologies\ese\files
\db2e\win32\x86.
2. For DB2e sync, add the DB2e drivers to your system path. They can be found
in the directory:
C:\Program Files\IBM\DeviceDeveloper\wsdd\wsdd5.0\technologies\ese\files
\db2eisync\win32\x86.
3. On your development system’s desktop, right-click My Computer and select
properties.
4. Select the Advanced tab and click the Environment Variables button.
5. Highlight PATH under System Variables and click Edit.
6. Add these directories, separated by a semicolon:
C:\Program Files\IBM\DeviceDeveloper\wsdd5.0\technologies\eswe\files\
db2e\win32\x86;C:\Program Files\IBM\DeviceDeveloper\wsdd5.0\technologies\
eswe\files\db2eisync\win32\x86
7. Click OK, then click OK again to save and close the properties window.
8. If it is currently running, restart WebSphere Studio so that the change will
become effective immediately.
Configuring the bundles
First we need to create a Bundle Project to hold the database classes.
1. If WebSphere Studio Site Developer is not running, click Start
Programs IBM WebSphere Studio Site Developer 5.1.x.
2. Open the SMF Perspective. Select Window Open Perspective SMF.
3. Make sure you are in the Package Explorer tab. Select File New
Other.
90 WCTME: Application Development and Case Study
4. Select Extension Services Extension Services Bundle Project and
Click Next.
5. Enter the Project name ITSORentalsDatabaseServiceBundle and click Next.
See Figure 4-2.
Figure 4-2 Selecting the DB2e application services
6. In the Platform Profile field choose Extension Services: jclFoundation
(5.7.0.).
7. Select the check boxes next to the application services DB2 Everyplace and
DB2 Everyplace ISync Client. Click Next.
Chapter 4. Database 91
8. Click the Projects tab and select the check box next to
ITSOCustomerBundle. Click Next.
Figure 4-3 Selecting other projects for this project’s build path
9. Select the check box next to Create Default Bundle Activator. Click Finish.
10.If you see a panel indicating the folder has changed, click Yes.
11.From the Package Explorer tab of the SMF Perspective, select the
ITSORentalsDatabaseServiceBundle Project you just created and
right-click. From the pop-up menu, select New Package.
92 WCTME: Application Development and Case Study
12.Enter the package name com.itso.rentals.database and click Finish.
13.Select the package just created and right-click. From the pop-up menu select
New Interface.
14.Enter the name ITSORentalsDatabaseService and click Finish.
15.Into the ITSORentalsDatabaseService.java window that opens, copy the
following code in Example 4-2:
Example 4-2 ITSORentalsDatabaseService code
boolean init(Properties p);
boolean update2Arrived(String contractID);
boolean update2Exited(String contractID);
boolean updateVechicleLocation(String contractID, String VechicleLocation);
Customer getCustomer(String contractID);
Vector getPendingCustomers();
Vector getArrivedCustomers();
InputStream getPicture(String customerID);
String sync(Properties userProps);
public String createLocalData();
public boolean insertPictures();
boolean resetDemo();
16.Save the file.
17.Select the package just created, right-click. From the pop-up menu select
New Class.
18.In the New Java Class window (Figure 4-4 on page 93), enter the name
ITSORentalsDatabaseImpl. In the Interfaces: field, click the Add button. Add
the Interface ITSORentalsDatabaseService. Click OK, then click Finish.
Tip: To help remove unresolved compiler errors, right-click in the source and
select Source Organize Imports.
Chapter 4. Database 93
Figure 4-4 Creating the class implementing an interface
19.Replace the class methods generated automatically with the code in
Example 4-3:
Example 4-3 Class methods
private boolean standAlone = true;
private String path = "ITSODatabase";
private Connection con;
private Statement st;
private ResultSet rs;
private String driver = "jdbc:db2e:" + path + File.separator + "rentals";
/** synchronize all access to DB2e */
private Object syncLock = new Object();
/* (non-Javadoc)
* @see
com.itso.rentals.ITSORentalsDatabaseService#init(java.util.Properties)
*/
public boolean init(Properties p) {

Get IBM Workplace Client Technology Micro Edition Version 5.7.1: Application Development and Case Study now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.