Chapter 16: JavaServer Pages: Part II

pages 16 - 29

Acronyms

Accessing a Database in JSP Pages

  1. Load the JDBC driver. The driver serves as a bridge between the JDBC (ODBC) classes and the database itself. Follow the steps on pages 20-22 to register a desired database as an ODBC data source.
  2. Define the connection URL.
  3. Establish the connection.
  4. Create a statement object.
  5. Execute a query or update the data.
  6. Process the results.
  7. Close the connection.

Take a look at the retrieveDB.jsp source code below. Each of these steps is documented in the code.

Java Classes Used (Documentation)

Sample Code

Exercise

Create a database that contains account names and passwords. Construct a JSP form/program that allows a user to login. The program should display an appropriate message depending on whether the user entered a valid account name and password. When you are finished, have either Jack or John verify the functionality of your JSP program. We will also look at the underlying code.