Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
Print Button
 
Training Index

Creating EJB Clients

by jGuru

[Help | API Docs | Short Course| Exercises]

This exercise implements two standalone client applications to use the MusicCD entity bean and Inventory session bean that you developed and deployed in the previous exercises.

Note: Due to a bug in the 1.0 release of the J2EE RI regarding composite primary keys, you must download the 1.2.1 release of the J2SDK, Enterprise Edition.

Prerequisites

Skeleton Code

Tasks


  1. Start the Cloudscape database server with the command-line command cloudscape -start.

  2. Start the J2EE RI using the command-line command j2ee -verbose. Pay attention to the output to make sure that J2EE loads the MusicStoreDB datasource which you set up in the previous exercise, Setting up the Database.

  3. Edit the MusicClient.java skeleton to obtain the JNDI context and use this context to get a reference to the MusicCDHome.

  4. Create a new MusicCD bean with the UPC code given in the skeleton and set its fields to the values shown in the skeleton. Or if you have a favorite CD of your own, you can use that data.

  5. Add code to find the MusicCD bean you just created in the database then print out the database values of the fields you set in the previous step.

  6. Compile and run your client application.

  7. Edit the MusicInventoryClient.java skeleton to obtain the JNDI context, and use this context to get a reference to the InventoryHome.

  8. Create a new Inventory bean.

  9. Create an instance of MusicData and fill it with information about CD's you want to insert into the database, then use the Inventory bean's business method to perform this task.

  10. Compile and run your client application.

Where help exists, the task numbers above are linked to the step-by-step help page.

Solution Source

As a solution, the source code for the client applications are providedas well as the MusicStoreClient.jar file, which holds the container-generated stubs and skeletons and other things needed for a standalone-client to communicate with the J2EETM server.

Demonstration

MusicClient produces standard output similar to the following, depending on your choice of data:

myhost> java -classpath %CLASSPATH%;
       MusicStoreClient.jar; \
%J2EE_HOME%
         \lib\j2ee.jar  musicstore.MusicClient
         
Title: Luna Nueva
Artist: Diego Torres
Type: Latin
Price: 12.58
myhost>

MusicInventoryClient should produce standard output similar to the following:

myhost> java -classpath %CLASSPATH%;MusicStoreClient.jar; \
        %J2EE_HOME%\lib\j2ee.jar  musicstore.MusicInventoryClient
Building new inventory...
Submitting new inventory...
New inventory added to database.
myhost>

Upon examination, the database should then reflect the added inventory. The exact contents of the database will of course depend on what CD information you inserted:

MusicCDDataNewInventory.gif

Exercises

Short Course

Copyright 1996-2000 jGuru.com. All Rights Reserved.


Print Button
[ This page was updated: 11-May-2000 ]
Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-2000 Sun Microsystems, Inc.
All Rights Reserved. Terms of Use. Privacy Policy.