database applications made easy with websphere ......eclipse wtp project extends the eclipse...

46
Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-C and Eclipse Skill Level: Intermediate Anitha Krishnasamy Senior Consultant, WebSphere BPTSE IBM Sridhar Kuna ([email protected]) Staff Software Engineer, WebSphere Adapters IBM 13 Feb 2008 This article offers a technical introduction to working with WebSphere® Application Server Community Edition V2.0, DB2 Express-C, and Eclipse with a sample database application development exercise. Section 1. Before you begin To create an environment for developing and hosting database applications that use Java™ Platform, Enterprise Edition (Java EE) technology, you need: A development platform or tool for developing your applications. A database for storing and retrieving data. A Java EE 5 compliant application server for your test and production environments so you can test and host your applications. Achieving this environment could actually be easier -- and considerably less expensive -- than you might expect, thanks to an ideal combination of software that you can obtain and use at no charge: Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-C and Eclipse Trademarks © Copyright IBM Corporation 2008. All rights reserved. Page 1 of 46

Upload: others

Post on 19-Apr-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

Database applications made easy with WebSphereApplication Server Community Edition, DB2Express-C and EclipseSkill Level: Intermediate

Anitha KrishnasamySenior Consultant, WebSphere BPTSEIBM

Sridhar Kuna ([email protected])Staff Software Engineer, WebSphere AdaptersIBM

13 Feb 2008

This article offers a technical introduction to working with WebSphere® ApplicationServer Community Edition V2.0, DB2 Express-C, and Eclipse with a sampledatabase application development exercise.

Section 1. Before you begin

To create an environment for developing and hosting database applications that useJava™ Platform, Enterprise Edition (Java EE) technology, you need:

• A development platform or tool for developing your applications.

• A database for storing and retrieving data.

• A Java EE 5 compliant application server for your test and productionenvironments so you can test and host your applications.

Achieving this environment could actually be easier -- and considerably lessexpensive -- than you might expect, thanks to an ideal combination of software thatyou can obtain and use at no charge:

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 1 of 46

Page 2: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

• Eclipse is a popular open source development platform.

• IBM DB2 Express-C is a full function data server capable of supportingboth relational and pure XML data storage.

• IBM WebSphere Application Server Community Edition V2.0 is alightweight, Java EE 5 certified application server from IBM, based onApache Geronimo.

Using these tools as a foundation, this tutorial explores some of the key features ofWebSphere Application Server Community Edition and DB2 Express-C, introducesyou to Eclipse and its plug-ins, and explains how to set up and use these productsand tools so you can develop and deploy a database application.

To follow the tasks described in this tutorial, you will need:

• IBM WebSphere Application Server Community Edition V2.0

• IBM DB2 Express-C 9.1

• Eclipse SDK 3.3 and Web Tools Platform 2.0

• WebSphere Application Server Community Edition V2.0 WTP ServerAdapter (formerly Eclipse plug-in)

See Resources to download this prerequisite software, all of which is available freeof charge.

The next sections describe features and setup tasks for the above software.Instructions for building and deploying a simple database application for WebSphereApplication Server Community Edition V2.0 will follow.

Section 2. About WebSphere Application ServerCommunity Edition

IBM WebSphere Application Server Community Edition V2.0 (hereafter calledCommunity Edition) is a free-to-use Java Platform, Enterprise Edition 5 (Java EE)certified application server with a very small footprint, based on Apache Geronimo2.0.1. Community Edition is built on a highly customizable and modular architecture,and functions as a framework that supports existing open source components,forming a complete Java EE application server package made up of over 30best-of-breed open source projects.

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 2 of 46

Page 3: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

Community Edition's wealth of rich features has made it extremely popular. Forexample:

• Community Edition is a Java EE 5 certified application server thatsupports Servlets 2.5, JSP 2.1, and EJB 3.0.

• Administration of local and remote servers can be easily performed usingeither commands or a GUI Web-based console.

• Diagnostic capabilities, such as enhanced logging, a class loader viewer,and a JMX browser, are available through the administrative console.

• Community Edition supports the Eclipse IDE (Europa V3.3 and WTP 2.0release).

• Sample applications are included with the product to demonstrate JavaEE 5 capabilities.

• The application server is easily customizable, based on the applicationscenario.

• Application high performance and high availability can be achievedthrough tuning and clustering.

• Enhanced application and administration security is provided throughvarious types of realms and SSL certificates.

• An excellent logging and tracing system supports simplifiedtroubleshooting.

• World class IBM support is available.

• Community Edition is available to use free of charge.

In addition, Community Edition provides:

• Database connector support for Apache Derby, IBM DB2, Oracle,Microsoft® SQL Server, MySql.

• Directory support for Apache Directory Server, IBM Tivoli® DirectoryServer, MS Active Directory, OpenLDAP Server, and Sun™ ONEDirectory Server.

• Integration capability with WebSphere MQ.

The Community Edition product package contains:

• IBM SDK, Java 2 Technology Edition

• Sample applications to demonstrate Java EE 5 capabilities

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 3 of 46

Page 4: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

• Community Edition Web Tools Platform (WTP) Adapter (formerly calledEclipse plug-in)

• JDBC drivers for Apache Derby and IBM DB2.

Community Edition comes pre-integrated with several open source projects so youcan immediately provide applications with external resource components, such as adatabase, a messaging server, and a directory server. Such open source projectsinclude:

• Apache Geronimo: An open-source Java EE application server projectthat provides the foundation for Community Edition.

• Apache Tomcat: A servlet container that is used in the ReferenceImplementation for Java Servlet and JavaServer™ Pages technologies.

• OpenEJB: An EJB container.

• Apache Derby: A robust, small footprint database server.

• ActiveMQ: JMS provider.

See Resources for more details on Community Edition features and systemrequirements.

Section 3. About DB2 Express-C

DB2 Express-C is a free-to-use data server capable of supporting both relational andpure XML storage. You can use DB2 Express-C for developing and deploying XML,C/C++, Java, .NET®, PHP, and other applications.

DB2 Express-C is optimized for powering Web services, Web 2.0, and SOA-basedsolutions, is available for both Linux® and Windows platforms, has simplifiedpackaging that makes it easy to transparently install from within an application, andfeatures all the autonomic manageability features of other DB2 database products,with which it is fully compatible and to which it is fully scalable. DB2 Express-C canbe run on up to two dual-core CPU servers, with up to 4 GB of memory, any storagesystem setup, and no database size restrictions.

To enable you to work effectively with the database system, DB2 Express-Cprovides many tools and facilities, including:

• Command line: Execute DB2 commands, database utilities, and SQL

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 4 of 46

Page 5: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

statements.

• Administrative functions: Run administrative tasks to manage databaseconnections and database objects, perform preventive maintenance,manipulate data, analyze queries, and manage applications.

• Monitoring features: Monitor database activity, analyze events, and viewmemory utilization.

• Database setup: Connect and monitor remote databases.

• Product information: Access the Information Center and get informationon product updates.

Application development encompasses the creation of database applications,migrating applications from other databases, creating stored procedures or userdefined functions, and programming applications with different applicationdevelopment tools. The DB2 database system comes with a variety of programmingfeatures, including routines that you can use (database objects that encapsulateprogramming and database logic related to a specific task), that run on the databaseserver, to supplement or extend your applications.

DB2 Express-C provides support for these popular integrated developmentenvironments (IDEs):

• Eclipse

• IBM Rational® Developer tools

• DB2 Database Add-ins for Visual Studio .NET

• DB2 Developer Workbench.

Programming languages supported by DB2 Express-C include:

• C/C++ and DB2 Call Level Interface (CLI) and ODBC: A dynamic SQLprogramming interface for creating C/C++ applications that access DB2databases.

• C/C++ and embedded SQL: DB2 applications developed using C/C++programming languages can use embedded SQL techniques to createapplications using static and dynamic SQL statements.

• Java and Java Database Connectivity (JDBC): Provides a standard setof interfaces and classes for accessing databases from Java applicationsusing SQL.

• Java and Embedded SQL for Java (SQLJ): SQLJ support for DB2database applications has been optimized for executing embedded SQLstatements within Java applications. Compared to using JDBC, SQLJ

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 5 of 46

Page 6: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

reduces the amount of Java application code required.

• Microsoft ADO.NET and Visual Basic .NET and Visual C# .NET: TheDB2 .NET data provider is an ADO.NET interface to DB2 databasesystems. By using the DB2 .NET data provider classes, your .NETapplications will have managed, secure, high-performance access to DB2data.

• PHP: An open source scripting language specially suited for Webdevelopment. You can access your DB2 database systems by using theibm_db2 PHP extension or the PHP Data Objects (PDO) driver.

• Perl: An open source scripting language. Using the DBD::DB2 driver withthe Perl Database Interface (DBI) module (available from the Perl DBIWeb site), you can create DB2 database applications with Perl.

See Resources for more details on DB2 Express-C features and systemrequirements.

Section 4. About Eclipse

Eclipse is a lightweight, Java-based, extensible development platform with whichyou can develop a variety of applications using Java, Java EE, PHP, C, C++, XML,and others. Eclipse is an open source IDE that is community-managed by theEclipse Foundation, a not-for-profit, member-supported organization whose projectsare focused on building an open development platform comprised of extensibleframeworks, tools, and runtimes for building, deploying, and managing softwareacross the lifecycle. As with other open source projects, Eclipse software isdeveloped by open source developers (called committers), and is volunteered orcontributed by organizations and individuals.

You can customize and extend your Eclipse environment by adding (or removing)plug-in packages to extend available features based on your applicationrequirements. For example, adding the Web Tools Platform (WTP) gives you theability to deploy your applications on Community Edition directly from Eclipse. TheEclipse WTP project extends the Eclipse platform with tools for developing Web andJava EE applications. It includes:

• Source and graphical editors for a variety of languages.

• Wizards and built-in applications to simplify development.

• Tools and APIs to support deploying, running, and testing applications.

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 6 of 46

Page 7: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

Community Edition requires the Eclipse WTP.

See Resources for more details on getting started with Eclipse

Section 5. Install and configure Community Edition

To help you get up and running, the next sections include general instructions tohelp you install and configure the software components you need to create yourdevelopment environment.

WebSphere Application Server Community Edition is a fully licensed productavailable for you to download and use for free (using Download Director, whichrequires a Java-enabled browser, provides pause-and-resume capability for largedownloads, high-speed transfer, and file access through firewalls). Be sure youreview all the system prerequisites for Community Edition and prepare yourenvironment accordingly before proceeding with the installation.

Support for Community EditionWhen you download Community Edition, you are automaticallyentitled to limited online support during the initial 30-day period atno charge. If you require IBM support and maintenance beyond thisinitial period, several fee-based support plans are available

After downloading, you can install the software using either a silent method or one ofthe installation wizards provided in the product download package for theseplatforms:

• For AIX®, Linux, or Solaris™: wasce_setup-version-unix.bin

• For Windows: wasce_setup-version-win.exe

See these Resources for more details on installing and getting started withCommunity Edition:

• Get started with WebSphere Application Server Community Edition

• Launcher and Installer options while installing WebSphere ApplicationServer Community Edition

• Silent installation of WebSphere Application Server Community Edition

Verify your installation

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 7 of 46

Page 8: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

To verify that Community Edition has been installed properly, start the server usingeither of these tasks:

• Select Start => Programs => IBM WebSphere => Application ServerCommunity Edition => Start the server.

• Execute the startup.bin/sh file from the <wasce_home>\bin folder, where<wasce_home> is the Community Edition installation directory.

Figure 1. Community Edition successful start

Figure 1 shows a successful server startup message, along with a list of applicationsand application modules deployed on the server.

Provided your installation was successful, launch the administrative console byaccessing this URL: http://hostname:portnumber/console, where portnumberrepresents the Tomcat Connector HTTP port. To login to the console, use thedefault admin user ID and password, which are system and manager, respectively.

System administration

Community Edition provides two ways for you to perform system administrationtasks:

• Administrative console

Community Edition's Web-based administrative console provides a user

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 8 of 46

Page 9: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

friendly interface for administering many aspects of the local or remoteserver. It's important to remember that the Web-based admin consoledepends on other components operating within the server (for example,OpenEJB) to function properly. If any of these components are stopped orremoved from the server configuration (for example, using theload="false" attribute in the corresponding <module ...> element inconfig.xml), your browser will report an HTTP 404 or Not Found errorwhen you attempt to access the console. See Resources for anintroduction to many common admin tasks that you can perform using theconsole.

• Commands

Commands for managing the server from a command prompt or terminalsession are also available for Community Edition. All commands arelocated in the <wasce_home>\bin folder where <wasce_home> is theCommunity Edition installation directory. (The one exception to this, theuninstaller command, is located in the <wasce_home>\_uninst folder.)

See the WebSphere Application Server product documentation in Resources fordetails on both system administration methods.

Section 6. Install and configure DB2 Express-C

As with Community Edition, DB2 Express-C is a fully licensed product available foryou to download and use for free. Be sure you review all the system prerequisites forDB2 Express-C and prepare your environment accordingly before proceeding withthe installation.

Support for DB2 Express-CA 12-month support subscription is available for DB2 Express-C.

After downloading DB2 Express-C, launch the installation wizard by executingsetup.exe/bin, and then follow the simple steps to complete the installation.

To work with DB2 Express-C after installation, you can launch either of theseinterfaces, which are delivered with the DB2 Client:

• DB2 Command Line Processor (CLP): A text-based interface you canuse to run DB2 commands, database utilities, and SQL statements.

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 9 of 46

Page 10: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

• DB2 Control Center: A graphical interface you can use to manage andadminister database systems, databases, and database objects. You canalso open other centers and tools from the Control Center.

Figure 2. DB2 Express-C first steps

If you are a novice user, the DB2 Express-C First Steps tool introduces you to basicdatabase maintenance tasks and directs you to information on how to use the CLPand the Control Center to perform some of these tasks. First Steps also points youto additional resources about DB2 database systems.

To launch DB2 First Steps, select Start => Programs => IBM DB2 => Setup Tools=> First steps.

See Resources to get a good headstart with DB2 Express-C.

Section 7. Install and configure Eclipse components

Community Edition requires the Eclipse Web Tools Platform (WTP) for developingand deploying applications. You must have these prerequisite project packagesinstalled before you you can install or use WTP:

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 10 of 46

Page 11: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

• Eclipse Platform (Platform, JDT, PDE)

• Eclipse Modeling Framework (EMF, XSD InfoSet, SDO)

• Graphical Editing Framework (GEF)

• Data Tools Platform (DTP)

You can download these packages separately or you can get them together in theWTP All-In-One zip package, which contains the complete set of prerequisitesoftware distributions from the Europa release so you can begin using WTPimmediately.

If you install the packages separately, you must first extract the basic Eclipseplatform to the local system directory, then extract the remaining packages under the<eclipse_home>\plugins directory in the sequence specified above, then extractWeb Tools Platform to the plugins directory.

Eclipse Workbench

The Eclipse Workbench is the environment in which all of your applicationdevelopment will be performed. To launch the workbench:

1. Navigate to the Eclipse home folder.

2. Execute the eclipse.exe/bin file or run the eclipse command under the<eclipse_home>\bin directory. If you are doing this for the first time, thenexecute the command with the clean option, eclipse -clean, whichmakes Eclipse recognize newly installed plug-ins.

3. Specify the directory path for your workspace. Eclipse SDK will store yourprojects in a folder called "workspace" (Figure 3).Figure 3. Eclipse workspace

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 11 of 46

Page 12: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

4. Figure 4 shows the Eclipse workbench environment with four mainpanels:

• Left panel lists your projects.

• Middle panel is where you can work on or code your project files.

• Right panel shows the outline of the work item in the center pane.

• Lower panel lists views to help you troubleshoot and deploy theproject.

(You can maximize or minimize any panel by double clicking on it.)Figure 4. Eclipse Workbench panels

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 12 of 46

Page 13: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

Section 8. Install and configure Community Edition WTPAdapter

Installation alternativeTo install the same plug-in offline, download and extract thewasce-eclipse-plugin-2.0.0-updatesite.zip file into your localdirectory, then click New Local Site... and point to that directory.Click OK and then Finish.

A new WTP server adapter is available that supports both Community EditionVersions 1.1.0.x and 2.0. To configure the WTP adapter for Community Edition V2.0:

1. Launch the installation wizard for new features and plug-ins in Eclipse byselecting Help => Software Updates => Find and Install (Figure 5).Figure 5. Launch Update Install manager

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 13 of 46

Page 14: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

2. Select Search for new features to install.

3. Select New Remote Site... and then add the download URL (Figure 6):http://download.boulder.ibm.com/ibmdl/pub/software/websphere/wasce/updates/.Figure 6. Specify remote repository URL

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 14 of 46

Page 15: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

4. Select the list of options that need to be installed through this plug-in,which include all the options selected in Figure 7.Figure 7. Select the options of features to install

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 15 of 46

Page 16: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

5. In the next panel, read and accept the terms in the license agreement.

6. The update manager will download the files from the remote repository. Ifyou prefer that this process be performed in the background, click theRun in Background button.

7. Click Install in the Feature Verification panel (Figure 8).Figure 8. Feature install verification

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 16 of 46

Page 17: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

8. When the system asks for restart, click Yes and restart the Eclipse SDKfor the changes to take affect.

Installation of the Community Edition adapter is now complete. You now need to addthe Community Edition runtime for application deployment.

Add Community Edition to the configuration

To add Community Edition so that it is listed in the Servers view:

1. Select Window => Show View => Other... (Figure 9).Figure 9. Add new view to Eclipse workbench

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 17 of 46

Page 18: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

2. In the list, expand the Servers section. Select Servers and click OK. TheServers view is added to the lower panel of the Eclipse workbench.

3. Right-click in the new Servers view, the select New => Server.

4. In the New Server dialog, select IBM WASCE v2.0 Server and then Next(Figure 10).Figure 10. Select Community Edition V2.0 server

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 18 of 46

Page 19: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

5. In the Edit Server Runtime dialog, select the proper JRE runtime versionfor the JRE field, then browse and select the Community Editioninstallation folder for the Application Server Installation Directory field(Figure 11).Figure 11. Specify applicable Community Edition installation values

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 19 of 46

Page 20: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

6. In the New Server dialog (Figure 12), enter appropriate values for theHostname, Administrator id, and Administrator password, and then clickFinish.Figure 12. Specify server administration values

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 20 of 46

Page 21: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

Your Community Edition server has now been successfully added to Eclipse.

Running Community Edition within Eclipse

You can operate Community Edition within Eclipse in one of three modes:

• Start Server mode

This is a typical server startup mode. When started in this mode, theserver gets started along with the applications deployed on the server.

To start the server in this mode, go to the Servers view, right-click on theserver, and then click the Start icon on the popup window. (The server

is automatically started when you right-click on a file and then select RunAs => Run on Server.)

• Debug mode

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 21 of 46

Page 22: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

If you want to debug your projects while a server is running, you can starta server in debug mode. Once the server is running in debug mode youcan run the projects that are associated with the server, and then stopand restart the server at any time. The status of the server is displayed inthe Status column of the Servers view. The status of the breakpoints inyour file is displayed in the Debug view.

To start the server in this mode, go to the Servers view, right-click on theserver, and then click the Debug icon . The status of the server

changes to debugging.

• Profile mode

Data related to an application's run time behavior can be collected andpresented in both graphical and tabular views while the application isrunning. This occurs in profile mode, where you can see which operationstake the most time; this can help you find and resolve memory leaks.Once you have started a server in profile mode, you can run the projectsthat are associated with its configuration, and then stop and restart theserver at any time. The status of the server is displayed in the Statuscolumn of the Servers view.

To start the server in this mode, go to the Servers view, right-click on theserver, and then select the Profile icon . The status of the server

changes to profiling.

To stop Community Edition, go to the Servers view, right-click on the server to bestopped, then click the Stop icon from the list. (You can also start or stop the

server by clicking the appropriate icon on the right corner of lower panel of Eclipse.)

To launch the administrative console, go to the Servers view and right-click on theserver you want to administer. Select the Launch WASCE Console option from thelist. Login to the console using your administrator’s ID and password (default valuesare system and manager, respectively.

Section 9. Create a sample application

With your environment setup now complete, this section presents an exercise tohelp you get some hands-on experience creating and deploying a Web applicationwith the Eclipse development platform. In this exercise, you will create a sample

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 22 of 46

Page 23: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

Web application that contains JSP and servlet pages.

Create an Eclipse project

1. To work with Java EE components easily, your Eclipse workbench shoulddisplay the Java EE perspective. In Eclipse, the current perspective isdisplayed in the right corner. If you need to change the perspective, selectWindow => Open Perspective => Other... => Java EE.

2. To create a new project in Eclipse, right-click on the left panel (the ProjectExplorer window), then select New => Project => Web => Dynamic WebProject, then click Next (Figure 13).Figure 13. Create new dynamic Web project

3. Specify your new Project name. For the purpose of this exercise, nameyour project Test (Figure 14). Also, select these values:

• Target Runtime: IBM WASCE v2.0

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 23 of 46

Page 24: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

• Configurations: Default Configuration for WASCE v2.0Do not check Add project to an EAR (this option is for creating anenterprise application). Click Next.Figure 14. Specify project name

4. Specify a value for Context Root, which provides the unique URL qualifierfor the applications deployed on the server. In this example, use Test(Figure 15).Figure 15. Specify context root for the project

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 24 of 46

Page 25: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

5. Select Generate Deployment Descriptor to generate the basictemplates of the deployment descriptors. (If you do not select this option,you can create the deployment descriptors later by right-clicking theproject, then select Java EE =>Generate Deployment Descriptor stub).Specify Version as 2.0.

6. Specify (optional) values for Group Id, Artifact Id, Version, and ArtifactType (Figure 16), then click Finish to create the Dynamic Web Project.Figure 16. Mentioning Artifact Id and Type for the deployment

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 25 of 46

Page 26: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

Upon successful creation, the Test project will display in the Project Explorer panel.

Create a JSP page

To create a sample JSP page:

1. In the Project Explorer panel, navigate to the new Test project.

2. Right-click on WebContent and select New (Figure 17).

3. Select JSP from the list that displays. (If JSP does not display, selectOther => Web => JSP).

4. In the New JavaServer Page panel, enter a name for the JSP, such asTest, and then click Finish. If successful, a Test.jsp file will be created inthe WebContent folder with the basic JSP template.Figure 17. Create new JSP page

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 26 of 46

Page 27: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

5. To launch the new JSP file for editing, navigate to the Test project in theProject Explorer, and then double click on the Test.jsp file.

6. For the purpose of this example, copy and paste the sample code shownin Listing 1 into the Test.jsp file. (This sample code displays "You are hereseeing the sample JSP page deployed on Community Edition 2.0!!" as abody message and "Community Edition 2.0 - Sample JSP Page" as a titlemessage.)Listing 1. Sample JSP code

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Community Edition 2.0 - Sample JSP Page</title></head><body>

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 27 of 46

Page 28: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

You are here seeing the sample JSP page deployed on Community Edition 2.0!!</body></html>

7. Save the JSP file.

Create a servlet

To create a sample servlet:

1. In the Project Explorer panel, navigate to the Test project.

2. Right-click on WebContent and select New => Other. Expand Web andselect Servlet.

3. For Java package, enter com.test.servlet, and for Class name, enterTestServlet. Click Next.Figure 18. Create sample servlet

4. In the next dialog, click the Add button to add initialization parametersand URL mappings.

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 28 of 46

Page 29: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

5. Next, on the Select Modifiers, interfaces to implement, and method stubsto generate panel, the items shown in Figure 19 should be checked bydefault. Click Finish to create the servlet.Figure 19. Specifying interfaces and methods in servlets

6. Upon successful creation, the TestServlet.java file will be created underJava resources, in the src\com.test.servlet folder with the basic servlettemplate.

7. To launch the file for editing, navigate to the Test project in the ProjectExplorer, and double-click on the TestServlet.java file.

8. For the purpose of this exercise, copy and paste the sample code fromListing 2 into the TestServlet.java file. (This sample code displays "Youare here seeing the sample JSP page deployed on Community Edition2.0!!" as a body message and "Community Edition 2.0 - Sample JSPPage" as a title message.)Listing 2. Sample servlet code

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 29 of 46

Page 30: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

package com.test.servlet;

import java.io.*;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;

/*** Servlet implementation class for Servlet: TestServlet**/public class TestServlet extends javax.servlet.http.HttpServlet implements

javax.servlet.Servlet {static final long serialVersionUID = 1L;

/* (non-Java-doc)* @see javax.servlet.http.HttpServlet#HttpServlet()*/

public TestServlet() {super();

}

/* (non-Java-doc)* @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,* HttpServletResponse response)*/

protected void doGet(HttpServletRequest request, HttpServletResponseresponse)

throws ServletException, IOException {

doPost(request,response);

}

/* (non-Java-doc)* @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,* HttpServletResponse response)*/

protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {

PrintWriter out = response.getWriter();out.println("<html><head><title>Sample Serlvet page on

Community Edition 2.0</title></head></html>");

out.println("<body>");out.println("<font align=Center face=\"Garamond\"> You are here seeingthe sample Servlet deployed on Community Edition 2.0..!!!</font>");out.println("</body></html>");

}}

9. Save the servlet file.

Deploy the sample application on Community Edition

Community Edition uses a Geronimo-specific deployment descriptor, also referred toas a deployment plan, which has a format that looks like a J2EE 1.4 deployment

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 30 of 46

Page 31: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

descriptor, but differs in that it is specific to the application server. It is an XML filebased on an XML schema that contains configuration information related to theapplication module or service.

The Community Edition WTP adapter for Eclipse provides an editor for Geronimodeployment plans with which you can easily modify the context root value, and addor modify resource references, security roles, dependencies, and so on.

Figure 20. Geronimo Deployment Plan Editor

Deployment alternativeIf you wish to use an alternative method for deployment, you canright-click on the Test project in the Project Explorer window, selectRun As => Run on Server, select the Community Edition server,then click Finish to deploy the project.

To deploy the sample application on Community Edition:

1. In the Servers view, right-click on the Community Edition server andselect Add or Remove Projects.

2. The Add and Remove Projects panel has two sections:

• Available projects lists the projects that are available in Eclipse.

• Configured projects lists the projects deployed on Community Edition(Figure 21).

Select the Test project from the Available projects list, click the Addbutton, then click Finish.Figure 21. Add and Remove Projects

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 31 of 46

Page 32: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

The project is now successfully deployed on the Community Edition server.

To remove (or undeploy) the project from the server, navigate to the Add andRemove Projects panel (Figure 21), select the project under Configured projects,click Remove, and then Finish.

To run the application you just deployed on Community Edition, access this URLusing a Web browser: http://localhost:portnumber/<context-root>/. (The value ofcontext-root can be found in the geronimo-web.xml file.) Alternatively, you can alsoclick the URL corresponding to your application from the Applications section of theWeb console.

Section 10. Create a database application

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 32 of 46

Page 33: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

Next, you can put together your main enterprise database application.

With your Web application built, you will now deploy another sample Web project,called StudentWeb, that uses DB2 Express-C as a backend database server, createa database pool for this application, then package everything in an EAR file anddeploy it all on Community Edition.

To do this will requires two additional tasks:

• Create the database and related components on the database server.

• Create a database pool (data source) in Community Edition.

Create a database

To create the database and tables required for the application:

1. Launch the DB2 Express-C Control Center by selecting Start =>Programs => IBM DB2 => General Administration Tools => ControlCenter.

2. Right-click on All Databases and select Create Database => Standard(Figure 22).Figure 22. Create database in DB2 Express-C Control Center

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 33 of 46

Page 34: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

3. Enter a database name, such as student, and click Finish.

4. Expand the new database, student, that you just created.

5. Right click on Tables then select Create.

6. Enter a name (you can use student again) and description for the table,then click Next.

7. Click the Add button to create the columns required for the table. Add thecolumns as shown in the table below for this sample project.Column name Data type Length

Rollno VARCHAR 30

Name VARCHAR 50

Dob VARCHAR 30

8. Click Finish when done. You have now created the database and therequired table for the sample database application.

9. Download the sample Web Archive (WAR) application included with thistutorial, StudentWeb, to your local system. StudentWeb uses the JSP for

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 34 of 46

Page 35: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

a display page (view) and a servlet for the controller logic. (This sampleapplication adds and displays records from a table called "student.") Inthe Project Explorer in Eclipse, right-click then select Import => WAR file.

10. Browse to the WAR file you want to import (Figure 23) and select the AddProject to an EAR option (the Web module will be packaged with EARfile later).Figure 23. Import WAR file

11. Click Finish. The Web module StudentWeb and the application moduleStudentWebEAR have been created and should be displayed in theProject Explorer panel.

Create a database pool

A database pool is a data structure that contains information about a specificdatabase that the JDBC driver needs in order to connect to that database.Community Edition provides database connection pools with which you can bind acertain database to JNDI and access it from your applications.

Listing 3 shows sample code for creating a database pool.

Listing 3. DB2 Express-C database pool deployment plan

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 35 of 46

Page 36: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

<?xml version="1.0" encoding="UTF-8"?><connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2">

<dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2">

<!-- Database pool name --><dep:moduleId>

<dep:groupId>console.dbpool</dep:groupId><dep:artifactId>studentpool</dep:artifactId><dep:version>1.0</dep:version><dep:type>rar</dep:type>

</dep:moduleId>

<!-- Dependency files --><dep:dependencies>

<dep:dependency><dep:groupId>com.ibm.db2</dep:groupId><dep:artifactId>db2jcc</dep:artifactId><dep:version>9.1</dep:version><dep:type>jar</dep:type>

</dep:dependency><dep:dependency>

<dep:groupId>com.ibm.db2</dep:groupId><dep:artifactId>db2jcc_license_cu</dep:artifactId><dep:version>9.1</dep:version><dep:type>jar</dep:type>

</dep:dependency></dep:dependencies>

</dep:environment>

<resourceadapter><outbound-resourceadapter>

<connection-definition><connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>

<connectiondefinition-instance><!-- Database Pool JNDI name -->

<name>studentpool</name><!-- Database Connection information -->

<config-property-setting name="Password">G00dluck</config-property-setting>

<config-property-setting name="Driver">com.ibm.db2.jcc.DB2Driver

</config-property-setting><config-property-setting name="UserName">Anitha

</config-property-setting><config-property-setting name="ConnectionURL">

jdbc:db2://localhost:50001/student</config-property-setting><connectionmanager>

<local-transaction/>

<!-- Database pool size --><single-pool>

<max-size>10</max-size><min-size>0</min-size><match-one/>

</single-pool></connectionmanager>

</connectiondefinition-instance></connection-definition>

</outbound-resourceadapter></resourceadapter>

</connector>

When you deploy the above code on Community Edition, the correspondingdatabase pool, named studentpool, is created on the server. To deploy the plan:

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 36 of 46

Page 37: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

1. For the purpose of this exercise, copy and paste the above code into anXML file called dbplan-file.xml.

2. Add this plan file to the top level of your EAR file directory structure, underEarContent.

3. Copy the RAR file fromGERONIMO_HOME/\repository\org\tranql\tranql-connector-ra\1.3\tranql-connector-ra-1.3.rarto the top level of your EAR file under EarContent.

Modify database connection information as appropriate for your environment (that is,database name, user ID, password, and so on).

• In the META-INF\geronimo-application.xml in EAR file

Listing 4 shows how to specify the resource references in thegeronimo-web.xml file.

Listing 4. Sample geronimo-application.xml

<?xml version="1.0" encoding="UTF-8"?>

<application xmlns="http://geronimo.apache.org/xml/ns/j2ee/application-1.2"xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.2"xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2"

application-name="StudentWebEAR">

<sys:environment><sys:moduleId> ---> Application module configuration<sys:groupId>default</sys:groupId><sys:artifactId>StudentWebEAR</sys:artifactId><sys:version>2.0</sys:version><sys:type>ear</sys:type>

</sys:moduleId></sys:environment>

<module><connector>tranql-connector-ra-13.rar</connector>---> Resource Adapter

<alt-dd>dbplan-file.xml</alt-dd>---> Database pool plan

</module>

</application>

You need to include XML file and the Resource adapter values in theGeronimo-application.xml file between <module> and </module> tags.This will create the corresponding database pool on the CommunityEdition server during application deployment. Make sure that the filenames are correct.

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 37 of 46

Page 38: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

Create the connection between your application and thedatabase pool

To enable your application to connect to the database through your new databasepool, you need to create a connection between the application and the databasepool. To do this, you need to declare a resource reference and map it to a specificconnection pool available to the application module (the module code must look upthe connection pool through JNDI.)

• In the WEB-INF/web.xml in the WAR file

Once the database pool has been deployed, application modules canrefer to it using the name specified in the configuration information. To dothis, declare a resource-ref with a type of javax.sql.DataSource in itsstandard J2EE deployment descriptor (web.xml). Listing 5 shows how tospecify the resource reference in the web.xml file.

Listing 5. web.xml

<resource-ref><res-ref-name>jdbc/MyDataSource</res-ref-name>---> Resource reference

<res-type>javax.sql.DataSource</res-type><res-auth>Container</res-auth><res-sharing-scope>Shareable</res-sharing-scope>

</resource-ref>

• In the WEB-INF/geronimo-web.xml in the WAR file

In the Geronimo deployment plan for that module, you need to specifywhich connection pool in the server will be used to satisfy the data sourcerequired by the Web module. To do this, you need to specify the name ofthe database pool to the ref-name which should be mapped with theresource-ref in web.xml. Listing 6 shows how to specify the resourcereference in the geronimo-web.xml file.

Listing 6. geronimo-web.xml

<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.2"

xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2"xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.2"xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">

<sys:environment><sys:moduleId>

<sys:groupId></sys:groupId>

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 38 of 46

Page 39: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

<sys:artifactId>StudentWeb</sys:artifactId><sys:version>2.0</sys:version><sys:type>war</sys:type>

</sys:moduleId></sys:environment>

<context-root>/StudentWeb</context-root>

<!-- security settings, if any, go here -->

<naming:resource-ref><naming:ref-name>jdbc/MyDataSource</naming:ref-name>---> Resource reference

<naming:resource-link>studentpool</naming:resource-link></naming:resource-ref>

</web-app>

The database pool name mentioned in your sample database applicationis "studentpool." You can find this value from the database pool plan inListing 4.

Application code for looking up the database connection pool

Listing 7 shows the code in the application module to lookup the created databaseconnection pool.

Listing 7. Application code

InitialContext ctx = new InitialContext();DataSource ds = ctx.lookup("java:comp/env/jdbc/MyDataSource");---> Resource referenceConnection con = ds.getConnection();

The JNDI lookup string is java:comp/env/ plus the res-ref-name used in web.xml(Listing3). Also, keep in mind that the resource reference name jdbc/MyDataSourceshould be the same in web.xml, geronimo-web.xml, and in the application code.

Deploy and launch the database application

To deploy the sample application in Community Edition:

1. In the Servers view, right-click on the Community Edition server.

2. Click on Add or Remove Projects.

3. Select the StudentWebWAR project from Available Projects and clickAdd (Figure 21).

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 39 of 46

Page 40: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

4. Click Finish. The project is now deployed on the Community Editionserver.

5. Once deployed, you can launch the application by accessing this URLfrom your Web browser: http://localhost:portnumber/<context-root>. TheURL for the sample StudentWebEAR database application is:http://localhost:portnumber/studentweb/.Figure 24. Sample database application

(The value of context-root can be found in the geronimo-web.xml file.Alternatively, you could also click the URL corresponding to theapplication in the Applications section of the Web console.)

Section 11. Troubleshooting

Should you encounter any errors during deployment, chances are it will be due toone of these issues:

Problem 1

Deployment failed:Unable to resolve resource reference 'jdbc/MyDataSource' (Couldnot findresource 'samplepool'. Perhaps it has not yet been configured,or yourapplication does not have a dependency declared for that

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 40 of 46

Page 41: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

resource module

Cause: This error occurs when the application tries to connect to a database poolthat does not exist on the server.

Solution: If you are bundling your Web application and the database pool in thesame EAR file, then make sure you are specifying the correct name for the databasepool in the Geronimo-web.xml file. This name can be found in the database pooldeployment plan. If you are deploying the Web application separately, then createthe database pool before you deploy the application.

Problem 2

Caused by: org.apache.geronimo.kernel.repository.MissingDependencyException:Unable to resolve dependency console.dbpool/studentpool//

atorg.apache.geronimo.kernel.repository.DefaultArtifactResolver.resolveInClassLoader(DefaultArtifactResolver.java:123)

atorg.apache.geronimo.kernel.repository.DefaultArtifactResolver.resolveInClassLoader(DefaultArtifactResolver.java:102)

atorg.apache.geronimo.kernel.repository.DefaultArtifactResolver$$FastClassByCGLIB$$e847b746.invoke(<generated>)

atnet.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)

atorg.apache.geronimo.gbean.runtime.FastMethodInvoker.invoke(FastMethodInvoker.java:38)

Cause: If you are bundling your Web application and the database pool deploymentplan in the same EAR file, you do not need to add the database pool as adependency in Geronimo-web.xml file like this:

<dependency><groupId>console.dbpool</groupId><artifactId>studentpool</artifactId>

</dependency>

This is only required when you are deploying the Web application and the databasepool separately. This error occurs when you add the database pool as a dependencywhen deploying both application and the database pool through same EAR.

Solution: Remove the dependency lines for the database pool from theGeronimo-web.xml file.

Problem 3

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 41 of 46

Page 42: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

Invalid alt vendor dd url: databaseplan-file.xmlorg.apache.geronimo.common.DeploymentException: Invalid alt vendor dd url:databaseplan-file.xml

atorg.apache.geronimo.j2ee.deployment.EARConfigBuilder.mapVendorPlans(EARConfigBuilder.java:1030)...Caused by: java.io.FileNotFoundException: JAR entry databaseplan-file.xmlnot found in C:\DOCUME~1\Anitha\LOCALS~1\Temp\geronimo-deployer8118.tmpdir\Junk.earat sun.net.www.protocol.jar.JarURLConnection.connect(Unknown Source)

Cause: This error occurs when the geronimo-application.xml file points to the wrongdatabase plan file.

Solution: Make sure that geronimo-application.xml points to the proper databaseplan and resource adapter file, as in this geronimo-application.xml code:

<module><connector> <resource adapter RAR file> </connector><alt-dd> <database pool plan file> </alt-dd>

</module>

Problem 4

22:47:50,265 ERROR [[jsp]] Servlet.service() for servlet jsp threw exceptionjava.lang.NullPointerExceptionat org.apache.jsp.student_jsp._jspService(student_jsp.java:106)at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)

Cause: This error occurs when there is a mismatch between the resource mappingsin web.xml and either the geronimo-web.xml file or resource JNDI lookup in theapplication code.

Solution: Make sure that resource reference in web.xml and geronimo-web.xml ismapping properly with the resource JNDI lookup code in the application.

Problem 5

22:59:10,359 WARN [ConnectorModuleBuilder] Problem loading driver class'com.ibm.db2.jcc.DB2Driver', possibly due to a missing dependency on the driverjar!!java.lang.ClassNotFoundException: com.ibm.db2.jcc.DB2Driver in classloader

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 42 of 46

Page 43: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

default/StudentWebEAR/2.0/ear

Cause: This error occurs when the database pool plan doesn’t contain the requireddependency JAR files.

Solution: Add the required driver JAR files in the database pool plan asdependencies, as in this code sample:

<dep:dependencies><dep:dependency>

<dep:groupId>com.ibm.db2</dep:groupId><dep:artifactId>db2jcc</dep:artifactId><dep:version>9.1</dep:version><dep:type>jar</dep:type>

</dep:dependency></dep:dependencies>

Section 12. Conclusion

This article offered a technical introduction to working with WebSphere ApplicationServer Community Edition V2.0, DB2 Express-C, and Eclipse with a sampledatabase application development exercise. The exercise provided hands-onexperience with:

• Installing and setting up the Community Edition, DB2 Express-C, andEclipse environments.

• Creating database artifacts required for the application.

• Developing a sample database application in Eclipse.

• Deploying the sample database application on Community Edition.

See the Resources section for a deeper understanding of these products, andexperiment further by deploying the sample applications available from theCommunity Edition download page, and with your own test applications.

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 43 of 46

Page 44: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

Downloads

Description Name Size Downloadmethod

0802_krishnasamy.ZIP 925 KB HTTP

Information about download methods

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 44 of 46

Page 45: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

Resources

Learn

• WebSphere Application Server Community Edition product documentation

• DB2 Express-C Information Center

• The Eclipse Foundation

• Eclipse documentation

• WebSphere Application Server Community Edition resources

• Get started with WebSphere Application Server Community Edition

• Using the Web console in WebSphere Application Server Community Edition

• Advanced administration in WASCE: Working with database realms andsecurity elements

• Get to know Java EE 5

• Recommended Eclipse reading list

• IBM developerWorks WebSphere

Get products and technologies

• Download IBM WebSphere Application Server Community Edition V2.0

• Download IBM DB2 Express-C 9.1

• Download Eclipse SDK 3.3 and Web Tools Platform 2.0

• Download WebSphere Application Server Community Edition V2.0 WTPAdapter (formerly Eclipse plug-in)

Discuss

• Forum: IBM WebSphere Application Server Community Edition and ApacheGeronimo

About the authors

Anitha Krishnasamy

ibm.com/developerWorks developerWorks®

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 45 of 46

Page 46: Database applications made easy with WebSphere ......Eclipse WTP project extends the Eclipse platform with tools for developing Web and Java EE applications. It includes: • Source

Anitha Krishnasamy is a Software Engineer working with theWebSphere BPTSE team in the IBM India Software Labs, Bangalore.Anitha's areas of expertise include business integration and J2EEtechnologies, and she holds a masters degree in ComputerApplications from the National Institute of Technology, Trichy, India.

Sridhar KunaSridhar Kuna is a Staff Software Engineer working with theWebSphere Adapters team in IBM India Software Labs, Bangalore. Hisarea of expertise includes business integration and J2EE technologies.Sridhar holds a Masters degree in Software Engineering from BirlaInstitute of Technology and Science, India.

developerWorks® ibm.com/developerWorks

Database applications made easy with WebSphere Application Server Community Edition, DB2 Express-Cand Eclipse

Trademarks

© Copyright IBM Corporation 2008. All rights reserved. Page 46 of 46