JDBC SIMPLE Sample Application

JDBC SIMPLE Sample Application


This document describes how to use the Java DataBase Connectivity (JDBC) SIMPLE sample application with the Sun Java System Web Server.

This sample application document contains the following sections:



Overview

 The JDBC SIMPLE application stores generated greetings in the database and allows you to retrieve all greetings that have been issued. The application "look and feel" is shown below.

  1. Bring up a web page with a form like the one in Figure 1.



    Figure 1   

  1. Enter a string and click the Process button.

    A servlet is invoked. This servlet is one of two controllers (there are two servlets) for the application
    .

    The servlet dispatches a JavaServer Pages (JSP) file to deliver the greeting back to the browser. The JSP serves as the view component of this application.

    After the JSP executes, Figure 2 displays.


    Figure 2

  1. Traverse the "here" link to invoke the other controller (a servlet) to retrieve all records from the table and display them using a JSP.

    As a result of the execution of the second JSP, you should see a page similiar to the one displayed in Figure 3.



    Figure 3

  1. Click the "here" link to return to the first page, and enter a new name for a greeting. Then view the recorded greetings again to see that additional greetings are retrieved from the database.


Setting Up the Environment

For information about creating and maintaining the database, refer to the database documentation.

For information about using the PointBase database with the Sun
Java System Web Server, refer to How to Run Sample Applications With PointBase.

For information about using the Oracle database withthe Sun
Java System Web Server, refer to How to Run Sample Applications With Oracle.

Note - Make sure that the necessary parameters for running the samples are specified in install_root/samples/java/webapps/common.properties.


Compiling and Assembling the Application


To compile and assemble the sample application, complete the following steps:

  1. If you want to run the sample on an Oracle database, you must use the following script to create the table Greeting: install_root/samples/java/webapps/jdbc/simple/src/sql/jdbc-simple-ora.sql

    If you want to run the sample on a PointBase database, you must use the following script to create the table Greeting: install_root/samples/java/webapps/jdbc/simple/src/sql/jdbc-simple-pb.sql

    See How to Run Sample Applications With PointBase or How to Run Sample Applications With Oracle.
  1. JDBC datasource can be created with the Administration GUI or CLI, or with the following method. Make sure that the necessary parameters for creating the JDBC resource are specified in the jdbc.build.properties file under the install_root/samples/java/webapps/jdbc directory. If you created the JDBC datasource using the Administration GUI or CLI, make sure that you added the JDBC driver jar files into the class-path-suffix element.

  2. Compile and assemble the WAR file by changing to the source directory at install_root/samples/java/webapps/jdbc/simple/src and running the ant command.

    The default target default is executed to build the WAR file.

  3. Execute ant create_datasource to create the data source.

    This creates the jdbc-resource element. Based on the jar files specified in the class.path.suffix property, the jar files will be added to the class-path-suffix element. For information about using the Administration GUI or CLI to create the data source, refer to Deploying Samples and Creating the Resources using Admin GUI.

    Note - If you want to delete the data source, execute ant delete_resource.

  4. Deploy the application.

    After you have re-created the sample application from scratch, you can proceed to Deploying the Sample Application.

  5. (Optional.) Clean the web application project area.

    # ant clean

    This removes the assemble and build directories for the sample application. The WAR file is now ready for deployment.


Deploying the Sample Application

To deploy the sample application, complete the following steps:
  1. Change to the source directory at install_root/samples/java/webapps/jdbc/simple/src.
  2. Run the ant tool using the deploy task.

    # ant deploy

If you want to verify registration of the application, proceed to Verifying Deployment. Otherwise, proceed to Running the Sample Application.
 

Verifying Deployment

To verify the registration and deployment of the application, complete the following steps:

  1. Change to the source directory at install_root/samples/java/webapps/jdbc/simple/src.

  2. Run the ant tool using the list_apps task.

    # ant list_apps

    The jdbc-simple module is listed as one of the components.

    Running the Sample Application

    You can run the application through the following URL:

    http://Sun_Java_System_Web_Server_hostname:port/jdbc-simple/index.html

    Undeploying the Sample Application
After successfully deploying and running the application, you might decide to undeploy it and remove the files.To undeploy the application, complete the following steps:
  1. Change to the source directory at install_root/samples/java/webapps/jdbc/simple/src.

  2. Run the ant tool using the undeploy task.

  3. # ant undeploy


  4. Run the ant tool using the delete_resource task.

    # ant delete_resource

     
    This removes the deployed resource.


Copyright © 2007 Sun Microsystems, Inc. All rights reserved.