本地这样连是可以的,如果是远程的话就请参照下面的代码
其中initialContextFactoryClassName, provideURL两个参数与具体应用服务器相关private void init(String initialContextFactoryClassName, String provideURL,
String jndi) {
try {
Context ctx;
if (initialContextFactoryClassName == null || provideURL == null) {
ctx = new InitialContext();
} else {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryClassName);
p.put(Context.PROVIDER_URL, provideURL);
ctx = new InitialContext(p);
}
Object objref = ctx.lookup(jndi);
OrgHelperHome home = (OrgHelperHome) PortableRemoteObject.narrow(objref,
OrgHelperHome.class);
helper = home.create();
} catch (RemoteException ex) {
Log.error(ex);
} catch (CreateException ex) {
Log.error(ex);
} catch (NamingException ex) {
Log.error(ex);
}
}
其中initialContextFactoryClassName, provideURL两个参数与具体应用服务器相关private void init(String initialContextFactoryClassName, String provideURL,
String jndi) {
try {
Context ctx;
if (initialContextFactoryClassName == null || provideURL == null) {
ctx = new InitialContext();
} else {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryClassName);
p.put(Context.PROVIDER_URL, provideURL);
ctx = new InitialContext(p);
}
Object objref = ctx.lookup(jndi);
OrgHelperHome home = (OrgHelperHome) PortableRemoteObject.narrow(objref,
OrgHelperHome.class);
helper = home.create();
} catch (RemoteException ex) {
Log.error(ex);
} catch (CreateException ex) {
Log.error(ex);
} catch (NamingException ex) {
Log.error(ex);
}
}
程序找不到本地接口,我到WEBLOGIC 上TEST一下,结果说EJB配置不对, 哪里不对也不清楚,倒死了
TblCourseResult sltCourse = null;
try {
javax.naming.Context ctx = new javax.naming.InitialContext();
TblCourseResultHome home = (TblCourseResultHome) ctx.lookup("TblCourseResult");
sltCourse = home.findByPrimaryKey(sltCourseID);
ctx.close();
}
catch (Exception ex)
{
String errorMessage = "按选课课号查询开课信息表信息时出错";
System.out.println(errorMessage);
ex.printStackTrace();
}