Writing a Client

Listing 11.9 demonstrates how a client accesses an entity bean.

Listing 11.9. The Full Text of day11\Client.java
 package day11; import java.util.*; import javax.naming.*; import javax.ejb.*; public class Client { public static void main(String[] args) { print("Starting Client . . .\n"); Context initialContext = null; OrderHome orderHome = null; Order order = null; try { print("Looking up the order home via JNDI.\n"); initialContext = new InitialContext(); Object object = initialContext.lookup("day11/Order"); orderHome = (OrderHome) javax.rmi.PortableRemoteObject.narrow(object,OrderHome.class); order = (Order)orderHome.create("1", "Submitted", 100); String orderId = order.getOrderId(); print("Created a new order:" + orderId + ...

Get Sams Teach Yourself EJB in 21 Days now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.