Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Building Web-based applications with JDBC

Robert Brunner (rjbrunner@pacbell.net), Astrophysicist , California Institute of Technology
Robert J. Brunner
Robert J. Brunner is an astrophysicist by day and a computer hacker by night. His principal employer is the California Institute of Technology, where he works on knowledge extraction and data-mining from large, highly distributed astronomical databases. He has provided consulting to scientific data centers around the world, provided Java and XML training to a variety of groups, and is currently working on the book Enterprise Java Database Programming which will be published by Addison Wesley in 2002.

Summary:  If you're interested in the various approaches to building Web applications that access a database through JDBC, then this tutorial is for you. In this hands-on guide, you'll learn the fundamentals of this process through three separate techniques: a servlet approach, a JavaServer Pages (JSP) page approach, and combined JSP, JavaBeans, and servlet approach (also known as Model Two).

Date:  19 Dec 2001
Level:  Intermediate PDF:  A4 and Letter (314 KB | 28 pages)Get Adobe® Reader®

Activity:  9203 views
Comments:  

About this tutorial

Should I take this tutorial?

If you're interested in the various approaches to building Web applications that access a database through JDBC, then this tutorial is for you. In this hands-on guide, you'll learn the fundamentals of this process through three separate techniques: a servlet approach, a JavaServer Pages (JSP) page approach, and combined JSP, JavaBeans, and servlet approach (also known as Model Two).

The example code in this tutorial has been developed to work with the DB2 Universal Database 7.2 (see JDBC and database resources for more details on DB2), but modifying the code to work with other databases is trivial due to the use of a DataSource object.

This tutorial assumes you work comfortably with the Java programming language and does not delve into the particulars of servlets or JSP technology (see Resources for further reading on these subjects). The techniques presented, however, build on the skills developed in Managing database connections with JDBC and Advanced database operations using JDBC, and we recommend that you complete these tutorials prior to starting this one.


Sample application design

The example code snippets used throughout this tutorial are based on a fictitious message board application. It allows multiple authors to post messages and incorporates a searchable message digest that summarizes the status of the message board. If you plan on working through the examples in this tutorial, we recommend that you complete the Advanced database operations with JDBC tutorial first; doing so ensures your environment is correctly installed and configured.

The simplified version of the message board application discussed in this tutorial has three distinct entities:

  • A message class
  • An author class
  • A digest class

Each of these entities has its own table in the database. The start page for the Web application displays the complete message digest. From the start page, a user is able to click on a message ID to display the associated message. Likewise, from a given message page, the user can click on a user ID to display the user profile (a picture in this case).


Tools for completing the tutorial

Although reading the examples helps you understand the concepts in this tutorial, most people learn better by actually trying out the examples for themselves. The following tools must be installed and working correctly before working through the examples:

  • A text editor: Java source files are simply text, so to create and read them, only a text editor is required. A Java IDE can also be used, but sometimes the IDE hides too many of the details.

  • A Java development environment, such as the Java 2 SDK, which is available at http://java.sun.com/j2se/1.4/: The Java 2 SDK, Standard Edition version 1.4, includes the JDBC standard extensions as well as JNDI (Java Naming and Directory Interface), both of which are necessary for some of the examples in this tutorial.

  • An SQL-compliant database: The examples in this tutorial have been tested with DB2 running on a Windows 2000 server, but because they are written using a DataSource object, they should easily convert to other databases, including Oracle and Microsoft SQL Server. Summary contains links to more information on both JDBC and databases.

  • A JDBC driver: Because the JDBC API is predominantly composed of interfaces, an actual JDBC-driver implementation must be obtained to make the examples in this tutorial work. The examples use advanced JDBC functionality, and, therefore, they require an advanced JDBC driver. Most database and JDBC driver vendors supply an evaluation version of a particular JDBC driver, including IBM, which provides a good JDBC driver for DB2.

  • A JSP page container: This type of container is required to build a JSP-based Web application. The reference implementation for both the servlet and JSP technology specification is the Apache Software Foundation's Jakarta Tomcat server, which is freely available, and is used throughout this tutorial.

  • The message board tables from the tutorial "Advanced database operations with JDBC": These tables were created and populated for use in a fictitious message board application. This tutorial builds on that application and requires those tables and data to properly function. The source code from this tutorial can be downloaded from Resources.

1 of 7 | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Java technology
ArticleID=131813
TutorialTitle=Building Web-based applications with JDBC
publish-date=12192001
author1-email=rjbrunner@pacbell.net
author1-email-cc=jaloi@us.ibm.com

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).