Writing a Client

Listing 10.11 demonstrates how a client accesses an entity bean.

Listing 10.11. The Full Text of day10/Client.java
 package day10; import java.util.*; import javax.naming.*; import javax.ejb.*; public class Client { public static void main(String[] args) { print("Starting Client . . ."); Context initialContext = null; StudentHome studentHome = null; Student student = null; try { print("Looking up the student home via JNDI."); initialContext = new InitialContext(); Object object = initialContext.lookup("day10/Student"); studentHome = (StudentHome) javax.rmi.PortableRemoteObject.narrow(object,StudentHome.class); String studentId = "raghava"; print("Creating a new student id:" + studentId + "."); object=(Student)studentHome.create(studentId, ...

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.