Sun ONE logo     
JDBC TRANSACTIONS Sample Application



JDBC TRANSACTIONS Sample Application


This document describes how to utilize the JDBC TRANSACTIONS sample application in conjunction with Sun ONE Application Server version 7.

This sample application document contains the following sections:



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 a session bean. 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 with DBMS vendor.)

To better understand the sample application source code, refer to the related javadocs which can be accessed at s1as_install_dir/samples/jdbc/transactions/javadocs/index.html after it is generated.


Setting up the environment

In order to successfully deploy and run the JDBC TRANSACTIONS sample application, Database resources (PointBase) needs to be setup with the Application Server. If you want to run JDBC TRANSACTIONS sample application with Oracle database, please refer to (How to run samples with Oracle database server) document.



Compiling and Assembling the Application



This section contains instructions to build and assemble the JDBC TRANSACTIONS sample application using a Command Line Interface (CLI).

  1. Go to s1as_install_dir/samples/jdbc/transactions/src/

    Execute the command asant



    Note You must add s1as_install_dir/bin to your path.



    The default target core will be executed to build the EAR file.

  2. Deploy the application.

    After you have re-created the sample application from scratch, you may proceed to Deploying the Sample Application. Step 3 is optional.

  3. Clean the application project area (optional).

    Execute the command asant clean to remove the sample application assemble and build directories.

    Now you are ready to use this ear file for deployment.



Deploying the Sample Application

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

Command Line-based Deployment describes how to manually register the application in Sun ONE Application Server using a Command Line Interface (CLI). This is the fastest means of deploying the sample application.

Since a complete EAR file is supplied, the fastest means of setting up the application is to use the command line utilities as described in this section.

The pre-built jdbc-transactions.ear file is a Enterprise Archive file that contains the JAR file of the application. Within the JAR file resides the XML deployment descriptor files, application class files, and other content required by the application.

Deploying the pre-built jdbc-transactions.ear file is simple. Deploy either by Using the asant script or by Using the asadmin command.


Using the asant script

  1. Go to the src directory of the sample. For example:

    s1as_install_dir/samples/jdbc/transactions/src

  2. Run asant using deploy task. For example:

    %asant deploy


Using the asadmin command

  1. Go to s1as_install_dir/samples/jdbc/transactions/

  2. Execute the following:

    asadmin deploy -u <user-name> -w <password> -H <hostname> -p <admin server port> --instance <instance name> jdbc-transactions.ear

The deployment process involves the following operations:

  • Authenticates against the local application server's administrative server

  • The EAR file is transferred to the administrative server

  • The administrative server begins the registration process:

    • Parses the EAR file and embedded JAR file

    • Explodes the bits into repository

    • Registers the J2EE application "jdbc-transactions" by updating server.xml

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


Verifying Deployment

As an optional step, you can use the Sun ONE Application Server Administration Tool to verify that the application has been registered. Otherwise, proceed directly to Running the Sample Application.

To verify the registration of the application, do the following:

Execute the command asadmin list-components to look at applications deployed with a server instance. For example:

asadmin list-components -u <username> -w <password> -H <host> -p <admin-port> <server instance name>.

You will see jdbc-transactions listed.


Undeploy the application

If you wish to undeploy the application after successful deployment, you may do so by either Using the asant script or by Using the asadmin command.


Using the asant script

  1. Go to s1as_install_dir/samples/jdbc/transactions/src

  2. Execute the following:

    asant undeploy


Using the asadmin command

  1. Go to s1as_install_dir/samples/jdbc/transactions/src

  2. Execute the following:

    asadmin undeploy -u <user-name> -w <password> -H <hostname> -p <admin server port> --instance <instance name> jdbc-transactions



Running the Sample Application

The schema/table are prepopulated so you don't need to configure the database. When the application is deployed, the jdbc-connection-pool and jdbc-resource are already taken care of. If you want to understand how to create/delete the jdbc-connection-pool/jdbc-resource, please refer to build.xml.

After the application is deployed,  run the client by:
  s1as_install_dir/bin/appclient -client s1as_install_dir/domains/<domain-instance>/<server-instance>/applications/j2ee-apps/jdbc-transactions_1/jdbc-transactionsClient.jar

The result should be:
    status = shipped



Troubleshooting



  • Please make sure that you run asant undeploy before redeploying this sample. Thiss will ensure that all modules are undeployed and the resources are disabled.

  • If you encounter problems when running the application, review the log files at s1as_install_dir/domains/<domain-instance> /<server-instance>/logs/server.log to learn what exactly went wrong.



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

Last Updated July 11, 2002