📄 facadebean.java
字号:
package cmpsample;
import javax.naming.*;
import java.util.Properties;
import javax.rmi.PortableRemoteObject;
import javax.ejb.*;
public class facadeBean implements SessionBean {
SessionContext sessionContext;
public Student student=null;
public StudentHome studentHome=null;
public void ejbCreate() throws CreateException {
/**@todo Complete this method*/
try{
Context context = new InitialContext();
//look up jndi name
Object ref = context.lookup("java:/comp/env/student");
//look up jndi name and cast to Home interface
studentHome= (StudentHome) ref;
}catch(Exception e){e.printStackTrace();}
}
public void ejbRemove() {
/**@todo Complete this method*/
}
public void ejbActivate() {
/**@todo Complete this method*/
}
public void ejbPassivate() {
try{
Context context = new InitialContext();
//look up jndi name
Object ref = context.lookup("java:/comp/env/student");
//look up jndi name and cast to Home interface
studentHome= (StudentHome) ref;
}catch(Exception e){e.printStackTrace();}
}
public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
}
public String getStuInfo(String stuid){
String strStu=null;
try{
student = studentHome.findByPrimaryKey(new Integer(stuid));
strStu ="the studentID is "+ student.getStuid() + " Name is "+student.getStuname();
}catch(Exception e){}
return strStu;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -