facadebean.java
来自「本书中的源代码是以JBuilder工程形式组织的」· Java 代码 · 共 52 行
JAVA
52 行
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 + =
减小字号Ctrl + -
显示快捷键?