Child pages
  • inventory - Simple Database Access Application
Skip to end of metadata
Go to start of metadata

This sample illustrates direct use of JDBC connections from a servlet. For details on outbound connection support see Connectors and Transaction Management (JDBC, JMS, J2CA, DataSource, Connection Pool, EIS). Generally direct use of JDBC is not advised unless you have performance constraints or need for dynamic jdbc (such as in a database browser) that make the use of JPA impractical.

This article is organized in to following sections.

Application Overview

The Inventory application in this article only supports three basic usecases of such applications.

  1. Add Items to the Stock
  2. Receive Items
  3. Issue Items
    The application workflow starts with adding item information to the stock. Then it allows enter goods receiving and issuing information. All those updated information are stored in the sample database, by default Derby.

The Inventory Web Application has following list of pages

  • Welcome
  • Add Item
  • Receive Goods
  • Issue Goods

The following figure illustrates the application flow.

Welcome page of the application acting as a notice board which displays current stock of each item. Through the Welcome page users can access Add Item, Receive Goods or Issue Goods Pages. Upon successful completion of each activity, the page will be redirected back to the Welcome page with updated stock information. Add Item helps to define items in the stock, then 0 number of items will be added to the stock. Receive and Issue Goods pages represent Goods Receiving and Issuing activities of the application respectively.

Application contents

The Inventory application consist of following list of packages and classes.

  • org.apache.geronimo.samples.inventory
    • Item - represents Item in the Inventory.
    • InventoryManager - represents list of services offered by the inventory.
  • org.apache.geronimo.samples.inventory.dao
    • ItemDAO - contains all database access methods.
  • org.apache.geronimo.samples.inventory.exception
    • DuplicateItemIdException - custom exception to handle duplication item id scenario.
    • ItemException - wraps data access exceptions (NamingException, SQLException).
    • NotSufficientQuantityException - Custom exception to handle not sufficient quantity situation.
  • org.apache.geronimo.samples.inventory.web
    • AddItemServlet - dispatch add item information to service layer.
    • IssueingServlet - dispatch issuing items information to service layer.
    • ReceivingServlet - dispatch receiving items information to service layer.

The list of web application files in the application is depicted in the following.

|- jsp
    +- add.jsp
    +- error.jsp
    +- issue.jsp
    +- recv.jsp
    +- geronimo-web.xml
    +- web.xml
|- welcome.jsp

This application defines a datasource with the help of the geronimo plan and web.xml deployment plans. The Geronimo plan from inventory-jetty or inventory-tomcat links the internal JNDI name "java:comp/env/jdbc/InventoryDS" to the sample database.


Following is the web.xml of the Inventory application. It declares the name "java:comp/env/jdbc/InventoryDS" used in ItemDAO to lookup the datasource.


Sample Database

The sample database that is being used to demonstrate this application is in-built Derby database. The name of the sample database is InventoryDB and it consists of two tables, namely ITEM and ITEM_MASTER. The fields for each of these tables are described below.

Table Name






The ITEM table stores the data related to the items while ITEM_MASTER stores the quantity in hand of each item.

Testing of the Sample Application

To test the sample application, open a browser and type http://localhost:8080/inventory. The Welcome page of Inventory application which is acts as a notice board will be loaded.

The user can directly access Add Items, Receive Goods and Issue Goods functionalities from the Welcome page.

  • No labels