| JDBC TRANSACTIONS Sample Application |
JDBC TRANSACTIONS Sample Application
This document describes how to use the Java DataBase Connectivity (JDBC) TRANSACTIONS sample application with Sun Java System Web Server.This document contains the following sections:
- Overview
- Compiling and Assembling the Application
- Deploying the Sample Application
- Running the Sample Application
- Undeploying the Sample Application
Overview
This sample application demonstrates the JDBC transaction. A JDBC transaction is controlled by the transaction manager of the DBMS. You might want to use JDBC transactions when wrapping legacy code inside a servlet.
To code a JDBC transaction, you invoke the commit and rollback methods of the java.sql.Connection interface. The beginning of a transaction is implicit. A transaction begins with the first SQL statement that follows the most recent commit, rollback, or connect statement. (This might vary by DBMS vendor.)
For information about creating and maintaining the database, refer to the database documentation.
For information about using the PointBase database with Sun Java System Web Server, refer to How to Run Sample Applications With PointBase.
For information about using the Oracle database with 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:
If you want to run the sample on an Oracle or a PointBase database, you must use the following script to create the tables inventory and order_item: install_root/samples/java/webapps/jdbc/transactions/src/sql/warehouse.sql
See How to Run Sample Applications With PointBase or How to Run Sample Applications With Oracle.
JDBC datasource can be created with the Administration GUI or CLI, or with the following method. Make sure the necessary parameters for creating the JDBC resource are specified in the jdbc.build.properties file in 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.
- Compile and assemble the WAR file by changing to the source directory at install_root/samples/java/webapps/jdbc/transactions/src and running the ant command.
The default target default is executed to build the WAR file.
- 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.
Deploy the application.
After you have created the sample application from scratch, you can proceed to Deploying the Sample Application.(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: If you want to verify registration of the application, proceed to Verifying Deployment. Otherwise, proceed to Running the Sample Application.
To verify the registration and deployment of the application, complete the following steps:
- Change to the source directory at install_root/samples/java/webapps/jdbc/transactions/src.
Run the ant tool using the list_apps task.
The jdbc-transactions module is listed as one of the components.
# ant list_apps
Running the Sample Application
You can run the application through the following URL:http://Sun_Java_System_Web_Server_hostname:port/jdbc-transactions/WarehouseServlet
The result should appear as follows:
shipped
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:
Copyright © 2007 Sun Microsystems, Inc. All rights reserved.