Make your own free website on Tripod.com

Developing EJB Clients
Gopalan Suresh Raj

Note
To work with any of these samples, you will need the following:
.........................................JDK 1.1.6 or higher (I use JDK 1.1.7A)
.........................................
The EJBHome version0.5.1 - a free EJB Server from http://www.ejbhome.com

To work with the EJB Servlet client, you will need
.........................................
JSDK 2.0 or higher

1. Define your TellerClient class

Define a class called TellerClient which is a client to our Session Enterprise Bean "Teller". Realize that our Session Bean Teller is itself a client to our Entity Bean "Checkings". As discussed in Modelling using Session and Entity Beans, we use our Session beans as the only interface to the client.

A Three-Tier Architecture for a Typical Bank

Figure shows what we are trying to ultimately accomplish in these pages here.

Bank\TellerClient.java
package Bank;

import java.rmi.*;
import java.util.*;

public class TellerClient
{

 public static void main(String[] args) throws Exception
 {

  TellerHome home = (TellerHome)Naming.lookup("Teller");
  System.out.println( "Naming.lookup successful..." );
  if( home == null )
  {
   System.out.println( "null TellerHome returned..." );
  }
  Teller teller = home.create();
  teller.createCheckingsAccount( "Athul", 100.0);
  teller.createSavingsAccount( "Aditya", 100.0);
  teller.TransferMoney( 50, 11, 10001);
  Checkings check = teller.getCheckings( 11);
  System.out.println("No = " + check.getAccountNumber() +
                     " Name = " + check.getCustomerName() +
                     " Balance = " + check.getBalance());
  Savings save = teller.getSavings( 10001);
  System.out.println("No = " + save.getAccountNumber() +
                     " Name = " + save.getCustomerName() +
                     " Balance = " + save.getBalance());
 }
}

2. Compile and run your client

E:\MyProjects\AccountEJB\Bank>javac TellerClient.java


E:\MyProjects\AccountEJB>cd ..

E:\MyProjects\AccountEJB>java Bank.TellerTest
Naming.lookup successful...
No = 0 Name = Athul Balance = 50.0
No = 0 Name = Aditya Balance = 150.0


E:\MyProjects\AccountEJB>

click here to go to
My EJB HomePage...

About the Author...
Gopalan Suresh Raj is a Software Architect, Developer and an active Author. He is contributing author to a couple of books "Enterprise Java Computing-Applications and Architecture" and "The Awesome Power of JavaBeans". His expertise spans enterprise component architectures and distributed object computing. Visit him at his Web Cornucopia site (http://www.execpc.com/~gopalan) or mail him at gopalan@execpc.com.

Go to the Component Engineering Cornucopia page

This site was developed and is maintained by Gopalan Suresh Raj

This page has been visited times since September 21,1998.

Last Updated : Dec 19, '98

If you have any questions, comments, or problems regarding this site, please write to me I would love to hear from you.


Copyright (c) 1997-98, Gopalan Suresh Raj - All rights reserved. Terms of use.

All products and companies mentioned at this site are trademarks of their respective owners.