![]() |
JDBC SIMPLE Sample Application |
JDBC SIMPLE Sample Application
This document describes how to use the JDBC SIMPLE sample application in conjunction with Sun ONE Web Server.This sample application document contains the following sections:
Overview
- Compiling and Assembling the Application
- Deploying the Sample Application
- Running the Sample Application
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 illustrated below.
Bring up a web page with a form like the one displayed in Figure 1.
![]()
Figure 1 Enter a string and press 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 JSP to deliver the greeting back to the browser. The JSP serves as the "view" component of our application.
As a result of the JSP execution, you will see Figure 2
Figure 2 Traverse the "here" link to invoke the other "controller" (a servlet) to retrieve all records from the table and display them via 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 Click the "here" link to return to the initial 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 Sun ONE Web Server, refer to How to run sample applications with Pointbase.
For information about using the Oracle database with Sun ONE Web Server, refer to How to run sample applications with Oracle.Compiling and Assembling the Application
This section contains instructions for compiling and assembling the sample application.
If you want to run the sample on an Oracle database, you must use the following script to create the table 'Greeting': <install_root>/plugins/java/samples/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>/plugins/java/samples/webapps/jdbc/simple/src/sql/jdbc-simple-pb.sql.Make sure you have added the JDBC driver jar to the classpathsuffix in server.xml.
Refer to How to run sample applications with Pointbase or How to run sample applications with Oracle.Make sure the necessary parameters for creating the jdbc and connection pool resources are specified in the build.xml file, as follows:
For a PointBase server database:
<!-- ======================================================= -->
<!-- data source & connection pool properties -->
<!-- ======================================================= -->
<property name="jdbc.datasource.name" value="jdbc/jdbc-simple"/>
<property name="jdbc.datasource.poolname" value="jdbc-simple-pool"/>
<property name="jdbc.connectionpool.poolname" value="jdbc-simple-pool"/>
<property name="jdbc.connectionpool.classname" value="com.pointbase.jdbc.jdbcDataSource"/>
<property name="jdbc.connectionpool.url" value="DatabaseName=jdbc:pointbase:server://<host name>/<database name>,User=<user name>,Password=<password>"/>
For an Oracle database:
<!-- ======================================================= -->
<!-- data source & connection pool properties -->
<!-- ======================================================= -->
<property name="jdbc.datasource.name" value="jdbc/jdbc-simple"/>
<property name="jdbc.datasource.poolname" value="jdbc-simple-pool"/>
<property name="jdbc.connectionpool.poolname" value="jdbc-simple-pool"/>
<property name="jdbc.connectionpool.classname" value="oracle.jdbc.pool.OracleDataSource"/>
<property name="jdbc.connectionpool.url" value="URL=jdbc:oracle:thin:@<host name>:<port>:<sid>,User=<user name>,Password=<password>"/>- Go to <install_root>/plugins/java/samples/webapps/jdbc/simple/src and execute ant
The target 'default' will be executed to build the WAR file.
Execute ant create_connectionpool to create the connection pool.
Execute ant create_datasource to create the data source.
(For information about using the Administration GUI to create the connection pool and data source, refer to Deploying Samples and Creating the Resources using Admin GUI.)
Then, restart the web server instance.
NOTE:
(a) Whenever you deploy or undeploy the connection pool and data source resource, you must restart the web server instance.
(b) If you want to delete the connection pool or change the connection pool properties, make sure you have already undeployed the relevant data source.
(c) If you want to delete the connection pool, execute ant delete_jdbcconnectionpool.
(d) If you want to delete the data source, execute ant delete_resource.
- Deploy the application.
- After you have created the sample application from scratch, you can proceed to Deploying the Sample Application. Step 6 is optional.
- Clean the application project area (optional).
Deploying the Sample Application
To deploy the sample application:If you want to verify registration of the application, proceed to Verifying Deployment. Otherwise, proceed to Running the Sample Application.
Go to the src directory of the sample: <install_root>/plugins/java/samples/webapps/jdbc/simple/src
- Run ant using the deploy task:
- Go to <install_root>/plugins/java/samples/webapps/jdbc/simple/src
- Execute the following command:
ant list_apps
http://<Web_Server_hostname>:<port>/jdbc-simple/index.html
Copyright © 2003 Sun Microsystems, Inc. All rights reserved.