JDBC TRANSACTIONS Sample Application

> JDBC TRANSACTIONS Sample Application
> This document describes how to use the JDBC TRANSACTIONS 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

> This sample application demonstrates the JDBC transaction. A JDBC transaction is controlled by the transaction manager of the DBMS. You may want to use JDBC transactions when wrapping legacy code inside of 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 rule is generally true, but may vary by DBMS vendor.)

> 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.

> 1. 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>/plugins/java/samples/webapps/jdbc/transactions/src/sql/warehouse.sql

> 2. 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.

> 3. 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-transactions"/>
>    <property name="jdbc.datasource.poolname" value="jdbc-transactions-pool"/>
>    <property name="jdbc.connectionpool.poolname" value="jdbc-transactions-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-transactions"/>
>    <property name="jdbc.datasource.poolname" value="jdbc-transactions-pool"/>
>    <property name="jdbc.connectionpool.poolname" value="jdbc-transactions-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>"/>

> 4. Go to <install_root>/plugins/java/samples/webapps/jdbc/transactions/src and execute the ant command.
>    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.

> 5. Deploy the application.
>    After you have re-created the sample application from scratch, you can proceed to Deploying the Sample Application. Step 6 is optional.

> 6. To clean the application project area (optional), execute the following command:

>    ant clean

> Deploying the Sample Application

> In this section, you will learn how to deploy the sample application.

> 1. Go to the src directory of the sample:

>    <install_root>/plugins/java/samples/webapps/jdbc/transactions/src/

> 2. Run ant using the deploy task:

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

> Verifying Deployment

> 1. Go to the src directory of the sample:
>    <install_root>/plugins/java/samples/webapps/jdbc/transactions/src/
> 2. Execute the following command:

> > ant list_apps
> > You will see the jdbc-transactions module displayed as one of the listed components.

> Undeploying the Application

> 1. Go to <install_root>/plugins/java/samples/webapps/jdbc/transactions/src

> 2. Execute the following:
>    ant undeploy

> Running the Sample Application

> You can run the application through the following URL:

> http://<Web_Server_hostname>:<port>/jdbc-transactions/WarehouseServlet

> The result should appear as follows:
> shipped

> Copyright © 2003 Sun Microsystems, Inc. All rights reserved.