EJB Projects

EJB Project 1

EJB Examples


How A client Invokes an EJB?
Previous Home Next

The all EJB clients implementing the steps to instantiating into a bean, and invoking its methods, and destroy the bean:

The home interface through a JNDI lookup. Follow JNDI and the EJB specification conventions for retrieving the bean reference, and including setting up JNDI properties if the bean is remote to the client. See How to Lookup the EJB Reference.

Narrow the returned object from the JNDI lookup to the home interface, as follows:

When accessing the remote interface, use the PortableRemoteObject.narrow method to narrow the returned object.

When accessing the local interface, cast the returned object with the local home interface type.

Create instances of the bean in the server through the returned object. Invoking the create method on the home interface causes a new bean to be instantiated and returns a bean reference.

Note: For entity beans that are already instantiated, you can retrieve the bean reference through one of its finder methods.Invoke business methods, which are defined in the component (remote or local) interface.After you are finished, invoke the remove method. This will either remove the bean instance or return it to a pool. The container controls how to act on the remove method.

package mypack;
import java.util.Scanner;
import javax.naming.InitialContext;
public class client
public static void main(Sting[] arg)
System.out.println("obtaining remote object...");
InitialContext IC=new initialContext();
Adder remote=(Adder) IC.lookup("adder");
System.out.println("Remoking object obtained invoking method");
Scanner.s=new Scanner(System.in);
System.out.println("Enter first No:");
int a=s.nextInt();
System.out.print("Enter Second No:");
int b=s.nextInt();
int c=remote.add(a,b);
System.out.println("Sum is"+c);
catch (Exception e)
Previous Home Next