📄 sessionaccountbean.java
字号:
package bankaccount;
import javax.ejb.DuplicateKeyException;
import javax.ejb.EJBException;
import javax.ejb.CreateException;
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 sessionAccountBean implements SessionBean {
private SessionContext ctx;
private entityAccountHome entityaccountHome;
public void setSessionContext(SessionContext c) {
ctx = c;
try {
Context ic = new InitialContext();
Object h = ic.lookup("java:/comp/env/ejb/entityAccountHome");
entityaccountHome=(entityAccountHome)
PortableRemoteObject.narrow(h,entityAccountHome.class);
} catch (NamingException ne) {
System.err.println("lookup entityAccountHome failed");
//ne.printStackTrace();
//throw new EJBException(ne);
}
}
public void enterNewAccount(int accountID,String ownerName,
float accountValue,int accountLevel)
{
try {
entityaccountHome.create(new Integer(accountID),ownerName,
accountValue,accountLevel);
} catch (DuplicateKeyException dke) {
// account already exists
System.out.println("Account with accountID: "+accountID
+" already exists.");
//throw new CreateException("Account with accountID: "+accountID
// +" already exists.");
} catch (Exception e) {
// unexpected error
System.out.println("Exception when execute enterNewAccount(()");
//e.printStackTrace();
//throw new EJBException(e);
}
}
public void ejbCreate() { System.out.println("sessionAccountBean:ejbCreate()"); }
public void ejbRemove() { System.out.println("sessionAccountBean:ejbRemove()"); }
public void ejbActivate() {}
public void ejbPassivate() {}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -