当前位置: 技术问答>java相关
ejb 菜鸟请进....................... ejb 之弱问题
来源: 互联网 发布时间:2015-07-15
本文导语: //////////// 接口 //////////////// public interface listHome extends EJBHome{ public list create()throws CreateException, RemoteException; public String findById( int Id ) throws FinderException,RemoteException; } /////////...
//////////// 接口 ////////////////
public interface listHome extends EJBHome{
public list create()throws CreateException, RemoteException;
public String findById( int Id )
throws FinderException,RemoteException;
}
///////////// 实现 ///////////////////////
public String ejbFindById( int aId )throws FinderException
{
try{
PreparedStatement ps = con.prepareStatement( "
SELECT Value From list WHERE Id=?" );
ps.setInt( 1, aId );
ResultSet re = ps.executeQuery();
if( re.next() ) return re.getString( 1 );
}catch( Exception e ){
System.err.println( e.getMessage() );
}
return null;
}
public String callClient( int aId )
{
try{
listHome home = (listHome)PortableRemoteObject.narrow(
new InitialContext().lookup("port:123"), listHome.class );
list obj = (list)home.create();
return home.findById(aId);
}catch( Exception e ){
System.err.println( "" + e.getMessage() );
}
return null;
}
/////////// 调用 /////////////////////////////
try{
SessionHome home = (SessionHome)PortableRemoteObject.narrow(
new InitialContext().lookup("port:234"), SessionHome.class );
Session se = (Session)home.create();
System.out.println( se.callClient(3) );
se.remove();
}catch( Exception e ){
System.err.println( "" + e.getMessage() );
/////////// 结果 ///////////////////////
RemoteException occurred in server thread; nested exception is: java.rmi.RemoteException:
nested exception is: java.lang.ClassCastException: _list_Stub;
nested exception is: java.lang.ClassCastException: _list_Stub
大哥帮帮忙看看那里出错了..........
|
home.create()已经是返回远程接口类型了,还造什么型
直接:list se=home.create();
直接:list se=home.create();