我没用过jb9 但需要连接组件吗??
我是写代码实现的
本地接口
private javax.naming.Context getinitContext()
{
try{
if (context==null) context = new javax.naming.InitialContext();
return context;
}
catch (Exception e)
{
throw new EJBException(e);
}
}
public void init() {
try{
context= this.getinitContext();
if (this.djYhszHome==null)
{
this.djYhszHome = (dzsb.ejb.entity.DjYhszHome) context.lookup("DjYhsz");
}
}
catch (Exception e)
{
}
public void add(String nsrsbh, String jitbm, String zsxmDm, String zxxmMc) throws MyException {
this.init();
try
{
dzsb.ejb.entity.DjYhszPK djyhszpk = new dzsb.ejb.entity.DjYhszPK(nsrsbh,
jitbm, zsxmDm, zxxmMc);
this.djYhsz = this.djYhszHome.findByPrimaryKey(djyhszpk);
throw new MyException("data is existed");
}
catch (FinderException e)
{
try
{
this.djYhsz = this.djYhszHome.create(nsrsbh, jitbm, zsxmDm , zxxmMc);
}
catch (Exception ex)
{
throw new MyException ("insert data error");
}
}
远程接口
java.util.Properties h = new java.util.Properties();
h.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"");
h.put(javax.naming.Context.DNS_URL,"t3://137.111.160.93");
javax.naming.InitialContext initContext =new javax.naming.InitialContext(h);
java.lang.Object xx = initContext.lookup("R_DjYhsz");
/////////////和本地接口的区别是 这里要用rmi
R_DjYhszHome r_djyhszhome = (R_DjYhszHome)
javax.rmi.PortableRemoteObject.narrow(xx,R_DjYhszHome.class);
R_DjYhsz r_djyhsz = r_djyhszhome.create();
DjYhszData[] dd= r_djyhsz.findall();