我现在改成下面这样,
在实体Bean依然有值,但在会话Bean中却报出了8个空值实体Bean>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  public Collection ejbFindSearch(String selectStr){
    ArrayList returnA = new ArrayList();
    selectStr = "select merc_id from merchandise where merc_id like '%d%'";
    try{
      makeConnection();
      PreparedStatement ps = connection.prepareStatement(selectStr);
      ResultSet rs = ps.executeQuery();
      System.out.println("try");
      while(rs.next()){
        this.setMercId(rs.getString(1));
        returnA.add(rs.getString(1));
        System.out.println("id>>>" + rs.getString(1));
      }
    }catch(Exception e){
      System.err.println("---err MerchandiseBean.ejbFindSearch():" + e.getMessage());
    }    return returnA;
  }
会话Bean>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  public Collection searchMerchandise(){
    Collection c;
    ArrayList returnA = new ArrayList();
    String id = "";    try{
      System.out.println("y111");
      c = merchandiseHome.findSearch("");
      Iterator iter = c.iterator();      while(iter.hasNext()){
        System.out.println("y222");
        merchandise = (Merchandise)PortableRemoteObject.narrow(iter.next(), Merchandise.class);
        id = merchandise.getMercId();
        returnA.add(id);
        System.out.println("id:::" + id);
      }
    }catch(Exception e){
      System.err.println("---err ControlBean.searchMerchandise():" + e.getMessage());
    }    return returnA;
  }

解决方案 »

  1.   

    merchandise = (Merchandise)PortableRemoteObject.narrow(iter.next(), Merchandise.class);
    ?取Home接口
    id = merchandise.getMercId();
    ?从Home接口取值 while(iter.hasNext()){
      id=(String)iter.next(); //既然已经取到值了,直接循环打印就行了。
    }
    参看jbuilder中范例:
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.rmi.PortableRemoteObject;import Converter;
    import ConverterHome;public class ConverterClient {   public static void main(String[] args) {
           try {
               Context initial = new InitialContext();
               Object objref = initial.lookup("MyConverter");           ConverterHome home = 
                   (ConverterHome)PortableRemoteObject.narrow(objref, 
                                                ConverterHome.class);           Converter currencyConverter = home.create();           double amount = currencyConverter.dollarToYen(100.00);
               System.out.println(String.valueOf(amount));
               amount = currencyConverter.yenToEuro(100.00);
               System.out.println(String.valueOf(amount));           currencyConverter.remove();       } catch (Exception ex) {
               System.err.println("Caught an unexpected exception!");
               ex.printStackTrace();
           }
       }