my dog learned polymorphism*
The moose likes EJB and other Java EE Technologies and the fly likes How to access complete table using a session bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How to access complete table using a session bean" Watch "How to access complete table using a session bean" New topic
Author

How to access complete table using a session bean

Abhishek Asthana
Ranch Hand

Joined: Sep 08, 2004
Posts: 146
Hi,
I want to print a table using a JSP page. I am using a DAO from a session bean to access the table and send the ResultSet back to the bean.


This is the code of the DAO interface:
public interface DataEJBDAO
{
public void init();

public java.sql.ResultSet giveResults() ;

}


This is the code of my stateless Bean:
public abstract class DataEJBBean implements SessionBean {
protected SessionContext ctx;
/**
* @ejb.interface-method
*view-type="remote"
* @dao.call name="giveResults"
**/
public java.sql.ResultSet giveResults(){
System.out.println("Entering DataEJBBean.giveResults");
System.out.println("Exiting DataEJBBean.giveResults");
return null;
}
public void setSessionContext(javax.ejb.SessionContext ctx)
{
this.ctx=ctx;
}

public void unsetSessionContext()
{
this.ctx=null;
}

}

And this is the Implementation of the DAO Interface:

public class DataEJBDAOImpl implements DataEJBDAO{

private DataSource jdbcFactory;

public void init(){
System.out.println("Entering DataEJBDAOImpl.init()");
InitialContext c=null;

if(this.jdbcFactory==null){

try{
c=new InitialContext();
this.jdbcFactory=(DataSource)c.lookup("java:comp/env/jdbc/OracleDS");
}catch(Exception e){
System.out.println("Error in DataEJBDAOImpl.init()");
System.out.println(e);
}
}
System.out.println("Leaving DataEJBDAOImpl.init()");
}

public java.sql.ResultSet giveResults()
{
Connection con=null;
PreparedStatement ps=null;
ResultSet rs=null;

try{
con=jdbcFactory.getConnection();
String query="select employeeName from employeePersonelDetails";
ps=con.prepareStatement(query);

rs=ps.executeQuery();
}catch(SQLException e){
e.printStackTrace();
System.out.println("Inside DataEJBDAOImpl.giveResults()"+e);
}
finally{
try{
rs.close();
ps.close();
con.close();
}catch(Exception e){
}
System.out.println("Leaving DataEJBDAOImpl.giveResults()");
return(rs);
}
}
}

But I am getting this error:

java.lang.reflect.UndeclaredThrowableException
at $Proxy1.giveResults(Unknown Source)
at myDAO.client.DAOClient.testBean(DAOClient.java:48)
at myDAO.client.DAOClient.main(DAOClient.java:67)
Caused by: java.io.NotSerializableException: oracle.jdbc.driver.OracleResultSetImpl
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
at java.rmi.MarshalledObject.<init>(MarshalledObject.java:92)
at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:363)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:534)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)
at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:135)
at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:87)
at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:45)
at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessionInterceptor.java:100)
at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
... 3 more
Exception in thread "main"

I am using JBoss 3.2.1

Can anyone please help me.
Thanks,
IJ
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You have an EJB method which returns a ResultSet, which is not a Serializable object (i.e. in this case it cannot be put into a format which an be passed over a network). Your ejb methods can only return Serializable object - so you need to convert your ResultSet into another structure, perpahs an ArrayList of DTOs or something.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to access complete table using a session bean
 
Similar Threads
An illegal attempt to commit a one phase capable resource with existing two phase
java.rmi.RemoteExcepion. Working with StatefulSessionBean
an easy test question relating to Bean Management Persistent
please check my code
ejbLoad is not getting called