gb=(Guestbook)PortableRemoteObject.narrow(gbIter.next(),Guestbook.class);--->gb = (Guestbook)gbIter.next();还有一个可能是你的数据源没有配置好,ejb服务器找得是自己默认的数据源

解决方案 »

  1.   

    你的那个bean类implements serializable了吗?串行化了吗?
      

  2.   

    seikoo,你所说的Bean类是指那个?package com.jeoky.ejb.guestbook;import javax.ejb.*;
    import java.util.*;
    import java.sql.*;public interface Guestbook extends javax.ejb.EJBLocalObject {
      public void setName(String name);
      public String getName();
      public void setSex(String sex);
      public String getSex();
      public void setQq(String qq);
      public String getQq();
      public void setEmail(String email);
      public String getEmail();
      public void setPhoto(String photo);
      public String getPhoto();
      public void setContent(String content);
      public String getContent();
      public void setPostdate(Timestamp postdate);
      public Timestamp getPostdate();
      public Integer getGuestbookId();
    }*************************************package com.jeoky.ejb.guestbook;import javax.ejb.*;
    import java.util.*;
    import java.sql.*;
    import javax.sql.*;
    import javax.naming.*;public class GuestbookBean implements EntityBean {
      EntityContext entityContext;
      java.lang.String name;
      java.lang.String sex;
      java.lang.String qq;
      java.lang.String email;
      java.lang.String photo;
      java.lang.String content;
      java.sql.Timestamp postdate;
      java.lang.Integer guestbookId;  private Connection conn;
      private String dbJndi="java:/MySqlDS";
      private String dbId="";
      private String dbPassword="";  public GuestbookPK ejbCreate(java.lang.Integer guestbookId) throws CreateException {
        setGuestbookId(guestbookId);
        return null;
      }
      public void ejbPostCreate(java.lang.Integer guestbookId) throws CreateException {
        /**@todo Complete this method*/
      }
      public void ejbRemove() throws RemoveException {
        /**@todo Complete this method*/
      }
      public void setName(java.lang.String name) {
        this.name = name;
      }
      public void setSex(java.lang.String sex) {
        this.sex = sex;
      }
      public void setQq(java.lang.String qq) {
        this.qq = qq;
      }
      public void setEmail(java.lang.String email) {
        this.email = email;
      }
      public void setPhoto(java.lang.String photo) {
        this.photo = photo;
      }
      public void setContent(java.lang.String content) {
        this.content = content;
      }
      public void setPostdate(java.sql.Timestamp postdate) {
        this.postdate = postdate;
      }
      public void setGuestbookId(java.lang.Integer guestbookId) {
        this.guestbookId = guestbookId;
      }
      public java.lang.String getName() {
        return name;
      }
      public java.lang.String getSex() {
        return sex;
      }
      public java.lang.String getQq() {
        return qq;
      }
      public java.lang.String getEmail() {
        return email;
      }
      public java.lang.String getPhoto() {
        return photo;
      }
      public java.lang.String getContent() {
        return content;
      }
      public java.sql.Timestamp getPostdate() {
        return postdate;
      }
      public java.lang.Integer getGuestbookId() {
        return guestbookId;
      }
      public GuestbookPK ejbFindByPrimaryKey(GuestbookPK pk) throws FinderException {
        /**@todo Complete this method*/
        return null;
      }
      public void ejbLoad() {
        /**@todo Complete this method*/
      }
      public void ejbStore() {
        /**@todo Complete this method*/
      }
      public void ejbActivate() {
      }
      public void ejbPassivate() {
      }
      public void unsetEntityContext() {
        this.entityContext = null;
      }
      public void setEntityContext(EntityContext entityContext) {
        this.entityContext = entityContext;
      }
      public java.util.Collection ejbFindAll() throws FinderException {
        /**@todo Complete this method*/
        Vector v=new Vector();
        try{
          System.out.println("ejbFindAll()");
          getConnection();
          PreparedStatement pds=conn.prepareStatement("select * from guestbook");
          ResultSet res=pds.executeQuery();
          while(res.next()){
            Integer id=new Integer(res.getInt("guestbook_id"));
            v.addElement(new GuestbookPK(id));
          }
          res.close();
          pds.close();
          conn.close();
        }catch(Exception ex){
          ex.printStackTrace();
        }
        return v;
      }  //取得资料库连结
      private void getConnection() throws NamingException, SQLException {    InitialContext ic=new InitialContext();
        DataSource ds=(DataSource) ic.lookup(dbJndi);
        conn= ds.getConnection(dbId, dbPassword);
        System.out.println("getConnection():OK");
      }
    }*********************************package com.jeoky.ejb.guestbook;import javax.ejb.*;
    import java.util.*;public interface GuestbookHome extends javax.ejb.EJBLocalHome {
      public Guestbook create(Integer guestbookId) throws CreateException;
      public Collection findAll() throws FinderException;
      public Guestbook findByPrimaryKey(GuestbookPK pk) throws FinderException;
    }***********************************package com.jeoky.ejb.guestbook;import java.io.*;public class GuestbookPK implements Serializable {  public Integer guestbookId;  public GuestbookPK() {
      }  public GuestbookPK(Integer guestbookId) {
        this.guestbookId = guestbookId;
      }
      public boolean equals(Object obj) {
        if (obj != null) {
          if (this.getClass().equals(obj.getClass())) {
            GuestbookPK that = (GuestbookPK) obj;
            return (((this.guestbookId == null) && (that.guestbookId == null)) || (this.guestbookId != null && this.guestbookId.equals(that.guestbookId)));
          }
        }
        return false;
      }
      public int hashCode() {
        return guestbookId.hashCode();
      }
    }