How do I get a list of records (like from a database query) in EJB?

sachin mahishi

[Basically, you have to cheat. Make a custom data class that is not an EJB. Create a Vector or List containing objects of this type, one per EJB; fill the data objects with the same values as are in the EJBs. Then you can return this List, and it will be serialized through RMI, and magically reconsituted on the client side. -Alex]

In your bean:

public get Vector getCustomerData()
{
 //Connect to DB

 //get result set

 Vector vector = new Vector();

 //iterate and build CustomerData object and add to vector

 return vector;
}
In your bean's remote interface:
  public Vector getCustomerData()
    throws RemoteException;
In both client and server:
public class CustomerData implements java.io.Serializable 
{
  private long id;
  private String name;

  public CustomerData(long id, String name)
  {
    this.id = id;
    this.name = name;
  }

  public long getId() {
    return id;
  }

  public String getName() {
    return name;
  }
}
In client (for ejb 1.0 lookups....)
  Context ctx = getInitialContext();
  //get initial context for lookup
  CustomerHome CustHome = (CustomerHome)ctx.lookup("Customer");
  Customer customer = CustHome.create();
  Vector v=customer.getCustomerData();
  // iterate through v 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact