📄 newcustomerbean.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 + -