JDBC TRANSACTIONS Sample Application |
JDBC TRANSACTIONS Sample Application
This document describes how to utilize the JDBC TRANSACTIONS sample application in conjunction with Application Server.This sample application document contains the following sections:
- Overview
- Compiling and Assembling the Application
- Deploying 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 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 <install_dir>/samples/jdbc/apps/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).
- Go to <nstall_dir>/samples/jdbc/apps/transactions/
- Execute the command asant
Note You must add <install_dir>/bin to your path.
- The default target core will be executed to build the EAR file.
- 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.
- 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.
NOTE: You must start the Database.
Please ensure that the database is started, (see How to start Database) before proceeding with deploying and running the sample application.
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 the 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.
- Go to the src directory of the sample. For example:
- <install_dir>/samples/jdbc/apps/transactions
- Run asant using deploy task. For example:
- %asant deploy
The deployment process involves the following operations:
- Go to <install_dir>/samples/jdbc/apps/transactions
- asadmin deploy --user <username> --password <password> --host <host> --port <admin-port> jdbc-transactions.ear
If you would like to verify the registration of the application, you may proceed to Verifying Deployment. Otherwise, proceed to Running the Sample Application.
- 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:
Verifying Deployment
As an optional step, you can use the 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 --user <username> --password <password>
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.
- Go to <install_dir>/samples/jdbc/apps/transactions
- asant undeploy
- asant unsetup [DO NOT RUN THIS STEP IF YOU ARE RUNNING THE jdbc-simple sample.]
- Go to <install_dir>/samples/jdbc/apps/transactions
- asadmin undeploy --user <username> --password <password> --host <host> --port <admin-port> jdbc-transactions
- asadmin delete-jdbc-resource --user <username> --password <password> --host <host> --port <admin-port>
jdbc/jdbc-transactions
asadmin delete-jdbc-connection-pool --user <username> --password <password> --host <host> --port <admin-port> jdbc-pool- [DO NOT EXECUTE THE LAST STEP IF YOU ARE RUNNING THE jdbc-simple sample.]
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:
<install_dir>/bin/appclient -client <install_dir>/domains/<domain_name>/applications/j2ee-apps/jdbc-transactions/jdbc-transactionsClient.jarThe result should be:
status = shipped
- Please make sure that you run asant undeploy before redeploying this sample. This 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 <install_dir>/domains/<domain_name>/logs/server.log to learn what exactly went wrong.
Copyright © 2004 Sun Microsystems, Inc. All rights reserved.
Last Updated March 6,
2004