Entity Beans  «Prev  Next»

Lesson 6 Looking at the complete code for the Customer client
ObjectiveWrite the complete code for the Customer client.

Complete Code Customer Client

Examine the code for the Customer client that follows. This class includes complete error handling and imports.
View the code below to see how all the parts that were explained before are combined together in one class.


import java.util.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

public class CustomerClient {
 public static void main(String[] args) {
  try {
   Context initial = new InitialContext();
   Object objref = initial.lookup("MyCustomer"); 
   CustomerHome home =  (CustomerHome)PortableRemoteObject.narrow
   (objref, CustomerHome.class);
   Customer mickey = home.create("111");
   mickey.setName("mickey");
   System.out.println("Created " + mickey.getInfo());
   mickey.remove("111");
   mickey = home.create("111");
   mickey.setName("mickey");
   System.out.println("Created " + mickey.getInfo());
   Customer goofy = home.create("333");
   goofy.setName("goofy");
   System.out.println("Created " + goofy.getInfo());
   System.out.println("Finding account 333 (goofy)");
   Customer bean1 = home.findByPrimaryKey("333");
   System.out.println("Found " + bean1.getInfo());
   if (bean1.isIdentical(goofy)) 
    System.out.println("bean1 is identical to goofy");
   else
    System.out.println("bean1 is not identical to goofy");
   } 
   catch (Exception ex) {
    System.err.println("Caught an exception." );
    ex.printStackTrace();
   }
 } 
} 

In the next lesson, the topics covered in this module will be reviewed.