I have a session bean, and this bean is used to connect to database. I want this bean to transfer a resultset to client, but it can't work. So I think that maybe I can use a class to store data and transfer data but I don't know how to do it. Hope someone help me figure out this. This is my code:
///////////////////////EJB
object
package Stateless;
import java.rmi.Remote;
import java.rmi.RemoteException;
import javax.ejb.*;
public interface ejbStateless extends EJBObject,Remote
{
public String sayHi() throws RemoteException;
public myOwn saveInfo(int a,int b) throws RemoteException;
}
////////////////EJB home
package Stateless;
import java.rmi.Remote;
import java.rmi.RemoteException;
import javax.ejb.*;
public interface ejbStateless extends EJBObject,Remote
{
public String sayHi() throws RemoteException;
public myOwn saveInfo(int a,int b) throws RemoteException;
}
/////////////////EJB bean
package Stateless;
import java.util.*;
import java.rmi.*;
import javax.ejb.*;
public class ejbStatelessBean implements SessionBean
{
private SessionContext ctx;
public void ejbCreate()
{
System.out.println ("ejb create");
}
public void ejbPassivate()
{
}
public void ejbActivate()
{
}
public void ejbRemove()
{
System.out.println ("ejb remove");
}
public void setSessionContext(SessionC
ontext ctx)
{
this.ctx=ctx;
}
public String sayHi() throws RemoteException
{
//System.out.println ("Hi");
return ("Chao ban");
}
public myOwn saveInfo(int a,int b) throws RemoteException
{
myOwn m=new myOwn();
m.a=a;
m.b=b;
return m;
}
}
////////////////////EJB Client
package Stateless;
import javax.naming.*;
import javax.rmi.*;
import java.rmi.*;
import java.util.Properties;
public class ejbStatelessClient
{
public static void main(String arg[])
{
String say;
System.out.println("\n Begin StatelessSession HelloClient Demo...\n");
try
{
Context ctx=new InitialContext();
Object objref=ctx.lookup("java:co
mp/env/Hel
lo");
ejbStatelessHome home=(ejbStatelessHome)Por
tableRemot
eObject.na
rrow(objre
f,ejbState
lessHome.c
lass);
System.out.println ("Create ejbStateless Client\n");
ejbStateless ejb1=home.create();
say=ejb1.sayHi();
myOwn m=new myOwn();
m=ejb1.saveInfo(1,3);
System.out.println (m.a);
System.out.println (m.b);
System.out.println (say);
}
catch(Exception e)
{
System.out.println (e.getMessage());
}
System.out.println ("\n End StatelessSession ");
}
}