January 27, 2021
Hot Topics:

Databases and Tomcat

  • By Sams Publishing
  • Send Email »
  • More Articles »


Using a database with Tomcat is straightforward so long as you apply the following simple, well-known design criteria:

  • Do not access the database directly from the servlet or JSP but encapsulate the database access in a Data Access Object (DAO) helper class. By putting all the database access code into a single class that is separate from the business and presentation logic of your application, you will simplify application maintenance and future feature enhancements.

  • To obtain best performance, you should use a connection broker class that implements database connection pooling. Tomcat includes the DBCP connection broker that is compatible with any JDBC driver.

DBCP uses a JNDI resource reference to separate database connection details from database data access. This separation of database administration information is an invaluable aid in managing the deployment of a Web application in different environments. Moving an application from development, to test, to production environments is a simple administrative issue that will not require changes to the Java code of the application.

About the Authors

The authors of this book work for Content Master Ltd., a technical authoring company in the United Kingdom specializing in the production of training and educational materials. For more information on Content Master, see its Web site at http://www.contentmaster.com. Previously, the authors contributed to Sams Teach Yourself J2EE in 21 Days (Sams, 2002).

Martin Bond, B.Sc., M.Sc., C.Eng., M.B.C.S., was born in Blackburn, England, in 1958, has honours and master's degrees in computer science, is a European Chartered Engineer, and has been working as a senior technologist for Content Master Ltd. for more than a year. After leaving university, Martin led an R&D team developing parallel processing compilers for the occam language, later moving into open systems software design and development working with Unix, C, C++, Oracle, and Windows NT. Since 1995, he has worked primarily as a trainer, course writer, and technical author specialising in Unix, C, C++, Java, and software design. He has written training courses on Unix, XML, Java, and Solaris Security and coauthored a book on J2EE. Martin currently lives on a smallholding in Cornwall, England.

Debbie Law, B.Sc., was born in Romsey, England, in 1959. Debbie started her career working on compiler development for parallel processing systems and later worked on the design and development of client/server applications. Debbie, also a senior technologist for Content Master Ltd., writes books, training material, and technical papers to pay the bills and maintains part of the Web site of a major UK charity for fun. She has an honours degree in computer science from Southampton University, England and currently lives on a smallholding in Cornwall, England.

Source of this material

This is Chapter 9: Databases and Tomcat from the book Tomcat Kick Start (ISBN:0-672-32439-3) written by Martin Bond and Debbie Law, published by Sams Publishing.

To access the full Table of Contents for the book

Other Chapters from Sams Publishing:

Web Services and Flows (WSFL)
Overview of JXTA
Introduction to EJBs
Processing Speech with Java
The Java Database Control in BEA Weblogic

Page 6 of 6

This article was originally published on April 1, 2003

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date