因为CoursesOnline项目使用Oracle 9i数据库,所以还需要把Oracle的驱动加载进来,Project -> Project Properties -> Path -> Required libraries,点击add,在Select One Or More Libraries窗口中选择OracleJDBCLib
OracleJDBCLib的配置请参考附录A.5.3 配置数据库驱动
6.2 创建Entity Bean(CMP)
6.2.1 新建一个EJB Module
File -> New -> Enterprise ->EJB Module
点击ok,并在接下来的窗口中为EJB Module命名为Courses,结果如下图
6.2.2 Import Schema From Database
在上图中的DataSources上点击右键,或者在Courses设计面板上点击右键,然后点击Import Schema From Database,在弹出的窗口中输入Driver,URL等参数,如下图所示
public class FacadeBean extends Object { private static final String ERROR_NULL_REMOTE = "Remote interface reference is null. It must be created by calling one of the Home interface methods first."; private static final int MAX_OUTPUT_LINE_LENGTH = 100; private CoursesFacadeHome coursesFacadeHome = null; private CoursesFacade coursesFacade = null;
//Construct the FacadeBean public FacadeBean() { initialize(); }
public void initialize() { try { //get naming context Context context = getInitialContext(); //look up jndi name Object ref = context.lookup("CoursesFacade"); //look up jndi name and cast to Home interface coursesFacadeHome = (CoursesFacadeHome) PortableRemoteObject.narrow(ref,CoursesFacadeHome.class);
Home Directory:选择Weblogic安装目录下的Server目录,如:C:/bea/weblogic700/server Main Class,VM Parameters:系统会自动获得,不用修改 Working Directory:创建的新Domain目录 如:C:/bea/user_projects/mydomain Class 中:由于没有Weblogic的SP包,删除weblogic_sp.jar包,仅保留weblogic.jar
JDK Install directory:选择安装Weblogic目录下的JDK目录 如:D:/bea/jdk131_03 BEA Home directory: 选择安装Weblogic目录 如:C:/bea User Name and Password:创建Domain时Administor的用户名称和密码。