已下为远程接口,本地接口和Bean类的代码:远程接口:
package ejb;import java.rmi.RemoteException;
import javax.ejb.EJBObject;//登陆注册远程接口类!!!!
public interface LoginEJBRemote extends EJBObject
{
    public String clientName() throws RemoteException;    public String clientPassword() throws RemoteException;    public String clientEmail() throws RemoteException;    public int loginCount() throws RemoteException;
}本地接口:
package ejb;import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
import javax.ejb.FinderException;//登陆注册本地接口
public interface LoginEJBHome extends EJBHome
{
    public LoginEJBRemote create(String cName, String cPassword, String cEmail) throws
        CreateException, RemoteException;    public LoginEJBRemote findByPrimaryKey(String cName, String cPassword) throws
        FinderException, RemoteException;
}

解决方案 »

  1.   

    Bean类:
    package ejb;import java.rmi.RemoteException;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import javax.ejb.CreateException;
    import javax.ejb.EJBException;
    import javax.ejb.EntityBean;
    import javax.ejb.EntityContext;
    import javax.ejb.FinderException;
    import javax.ejb.NoSuchEntityException;
    import javax.ejb.ObjectNotFoundException;
    import javax.naming.InitialContext;
    import javax.sql.DataSource;//登陆注册的EJB类
    public class LoginEJB implements EntityBean
    {
        private String cName;
        private String cPassword;
        private String cEmail;
        private int count;    private EntityContext context;    private Connection con;    //业务方法实现
        public String clientName() throws RemoteException
        {
            return cName;
        }    public String clientPassword() throws RemoteException
        {
            return cPassword;
        }    public String clientEmail() throws RemoteException
        {
            return cEmail;
        }    public int loginCount() throws RemoteException
        {
            this.count = this.count + 1;
            return this.count;
        }    public void setEntityContext(EntityContext context)
        {
            this.context = context;
            try
            {
                String dbName = "java:comp/env/jdbc/Music";            InitialContext cn = new InitialContext();
                DataSource ds = (DataSource) cn.lookup(dbName);            con = ds.getConnection();
            }
            catch(Exception e)
            {
                System.out.println(e);
                e.printStackTrace();
            }
        }    public void unsetEntityContext()
        {
            try
            {
                con.close();
            }
            catch(Exception e)
            {
                System.out.println(e);
                e.printStackTrace();
            }
        }    public String ejbCreate(String cName, String cPassword, String cEmail) throws
            CreateException
        {
            try //插入注册信息
            {
                String sql = "insert Client_Table values(?,?,?,?)";
                PreparedStatement sta = con.prepareStatement(sql);
                sta.setString(1, cName);
                sta.setString(2, cPassword);
                sta.setString(3, cEmail);
                sta.setInt(4, 1);
                sta.executeUpdate();
                sta.close();
            }
            catch(Exception e)
            {
                throw new EJBException("ejbCreate: " + e.getMessage());
            }        this.cName = cName;
            this.cPassword = cPassword;
            this.cEmail = cEmail;
            this.count = 1;        return cName;
        }    public void ejbPostCreate(String cName, String cPassword, String cEmail) throws
            CreateException
        {}    public String ejbFindByPrimaryKey(String PrimaryKey, String cPassword) throws
            FinderException, SQLException
        {
            //登陆信息验证
            String sql =
                "select cName from Client_Table where cName=? and cPassword=?";
            PreparedStatement sta = con.prepareStatement(sql);
            sta.setString(1, PrimaryKey);
            sta.setString(2, cPassword);
            ResultSet result = sta.executeQuery();
            if(result.next())
            {
                sta.close();            return PrimaryKey;
            }
            else
            {
                sta.close();
                throw new ObjectNotFoundException("ejbFindByPrimaryKey: " +
                                                  PrimaryKey + " 该用户不存在!");
            }
        }    public void ejbRemove()
        {}    public void ejbActivate()
        {
            this.cName = (String) context.getPrimaryKey();
        }    public void ejbPassivate()
        {
            this.cName = null;
        }    public void ejbLoad()
        {
            try
            {
                loadRow();
            }
            catch(Exception e)
            {
                throw new EJBException("ejbLoad: " + e.getMessage());
            }
        }    public void ejbStore()
        {
            try
            {
                storeRow();
            }
            catch(Exception e)
            {
                throw new EJBException("ejbStore: " + e.getMessage());
            }
        }    public void loadRow() throws SQLException
        {
            String sql =
                "select cPassword,cEmail,iCount from Client_Table where cName=?";
            PreparedStatement sta = con.prepareStatement(sql);
            sta.setString(1, cName);
            ResultSet result = sta.executeQuery();        if(result.next())
            {
                this.cPassword = result.getString(1);
                this.cEmail = result.getString(2);
                this.count = result.getInt(3);            sta.close();
            }
            else
            {
                sta.close();
                throw new NoSuchEntityException("用户 " + cName + " 的数据没有找到,无法读入!");
            }
        }    public void storeRow() throws SQLException
        {
            String sql =
                "update Client_Table set cPassword=?,cEmail=?,iCount=? where cName=?";
            PreparedStatement sta = con.prepareStatement(sql);
            sta.setString(1, cPassword);
            sta.setString(2, cEmail);
            sta.setInt(3, this.count);
            sta.setString(4, cName);
            int i = sta.executeUpdate();
            sta.close();
            if(i == 0)
            {
                throw new NoSuchEntityException("用户 " + cName + " 的数据没有找到,无法更新!");
            }
        }
    }请各位大侠指点这个问题改怎么解决,由于我是初学者,所以请详细解答,非常感谢!!!!