⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newcustomerbean.java

📁 java的一系列产品中包括jsme,jmse,j2ee,本文件提供j2ee实现的源代码.
💻 JAVA
字号:
package bankaccount;

import javax.ejb.DuplicateKeyException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;

public class NewCustomerBean implements SessionBean {

  private SessionContext ctx;
  private CustomerHome customerHome;

  public void setSessionContext(SessionContext c) {
    ctx = c;
    try {
      Context ic = new InitialContext();
      Object h = ic.lookup("java:/comp/env/ejb/CustomerHome");

      customerHome = (CustomerHome) 
        PortableRemoteObject.narrow(h, CustomerHome.class);

    } catch (NamingException ne) {
      ne.printStackTrace();
      throw new EJBException(ne);
    }
  }

  public void ejbCreate() {}
  public void ejbRemove() {}

  public void ejbActivate() {}
  public void ejbPassivate() {}

  public void enterNewCustomer(int id, String firstName,String lastName,  
    String emailAddress)  throws InvalidCustomerException
  {
    try {
      customerHome.create(new Integer(id),firstName,lastName,emailAddress);

    } catch (DuplicateKeyException dke) {
      // customer already exists
      throw new InvalidCustomerException("Customer with id: "+id
        + " already exists.");
    } catch (Exception e) {
      // unexpected error
      e.printStackTrace();
      throw new EJBException(e);
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -