newcustomerbean.java
来自「java的一系列产品中包括jsme,jmse,j2ee,本文件提供j2ee实现的」· Java 代码 · 共 55 行
JAVA
55 行
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 + =
减小字号Ctrl + -
显示快捷键?