<p>How to return ResultSet type from EJB to Servlet</p>
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Edward_Edward
Posted On:   Saturday, June 1, 2002 02:10 AM

I have a question about EJB.I want to get ResultSet by search data from Oracle DB,my steps are follows:first I visit Servlet with IE,then call EJB from Servlet,at last search data from Oracle through EJB.But I got many errors, //Servlet file which named "GetUserIdentity.java" public class GetUserIdentity extends HttpServlet { public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException { try { Properties prop=new Properties(); prop.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory"); prop.put(Context.PROVIDER_URL,"t3://192.168.39.152:7001"); Context ctx=new Init   More>>

I have a question about EJB.I want to get ResultSet by search data from Oracle DB,my steps are follows:first I visit Servlet with IE,then call EJB from Servlet,at last search data from Oracle through EJB.But I got many errors,
//Servlet file which named "GetUserIdentity.java"

public class GetUserIdentity extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
try
{
Properties prop=new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
prop.put(Context.PROVIDER_URL,"t3://192.168.39.152:7001");
Context ctx=new InitialContext(prop);
Object objref=ctx.lookup("CheckPassword");
CheckPasswordHome home=(CheckPasswordHome)javax.rmi.PortableRemoteObject.narrow(
objref,CheckPasswordHome.class);
CheckPassword ss=home.create();
ResultSet message;
message=ss.TableInfo();
...
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

//EJB file which named "CheckPassword.java"
package loginEJB;
import java.rmi.RemoteException;
import java.sql.ResultSet;
import java.util.Enumeration;
import java.util.Properties;

public interface CheckPassword extends javax.ejb.EJBObject
{
ResultSet TableInfo() throws java.rmi.RemoteException;
}

//The file "CheckPasswordEJB.java"

import java.sql.Statement;
import java.sql.ResultSet;
import java.util.Enumeration;
import java.util.Properties;
public class CheckPasswordEJB implements javax.ejb.SessionBean
{
public void ejbCreate()
{
System.out.println("ejbCreate() called");
}
...
public ResultSet TableInfo() throws java.rmi.RemoteException
{
String driverClass="oracle.jdbc.driver.OracleDriver";
String url="jdbc:oracle:thin:@as_server:1526:db817";
Connection connection;
try
{
// Oracle Client - Server Thin Driver
Class.forName(driverClass);
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
try
{
connection=DriverManager.getConnection(url,"eino","eino");
Statement stmt=connection.createStatement();
stmt.executeQuery("select * from table_info_tbl");
ResultSet rs=stmt.getResultSet();
return rs;
}
catch(SQLException e)
{
e.printStackTrace();
return null;
}
}
}

When I visit EJB,I got errors:
Starting service Tomcat-Standalone
Apache Tomcat/4.0.1
Starting service Tomcat-Apache
Apache Tomcat/4.0.1
java.rmi.MarshalException: error marshalling return; nested exception is:
java.io.NotSerializableException: oracle.jdbc.driver.OracleResultSetImpl


Start server side stack trace:
java.rmi.MarshalException: error marshalling return; nested exception is:
java.io.NotSerializableException: oracle.jdbc.driver.OracleResultSetImpl

java.io.NotSerializableException: oracle.jdbc.driver.OracleResultSetImpl
at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1148)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
at weblogic.common.internal.ChunkedObjectOutputStream.writeObject(Chunke
dObjectOutputStream.java:102)
at weblogic.common.internal.ChunkedObjectOutputStream.writeObject(Chunke
dObjectOutputStream.java:108)
at loginEJB.CheckPasswordEJB_28r6w3_EOImpl_WLSkel.invoke(Unknown Source)

at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:296)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerR
ef.java:93)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.jav
a:265)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest
.java:22)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
End server side stack trace
; nested exception is:
java.io.NotSerializableException: oracle.jdbc.driver.OracleResultSetImpl


Start server side stack trace:
java.io.NotSerializableException: oracle.jdbc.driver.OracleResultSetImpl
at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1148)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
at weblogic.common.internal.ChunkedObjectOutputStream.writeObject(Chunke
dObjectOutputStream.java:102)
at weblogic.common.internal.ChunkedObjectOutputStream.writeObject(Chunke
dObjectOutputStream.java:108)
at loginEJB.CheckPasswordEJB_28r6w3_EOImpl_WLSkel.invoke(Unknown Source)

at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:296)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerR
ef.java:93)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.jav
a:265)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest
.java:22)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
End server side stack trace

java.io.NotSerializableException: oracle.jdbc.driver.OracleResultSetImpl

Start server side stack trace:
java.io.NotSerializableException: oracle.jdbc.driver.OracleResultSetImpl
at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1148)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
at weblogic.common.internal.ChunkedObjectOutputStream.writeObject(Chunke
dObjectOutputStream.java:102)
at weblogic.common.internal.ChunkedObjectOutputStream.writeObject(Chunke
dObjectOutputStream.java:108)
at loginEJB.CheckPasswordEJB_28r6w3_EOImpl_WLSkel.invoke(Unknown Source)

at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:296)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerR
ef.java:93)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.jav
a:265)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest
.java:22)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
End server side stack trace

< >

I don't know why my program is error.
Any idea will be appreciated! How to correct ?
Edward

   <<Less

Re: <p>How to return ResultSet type from EJB to Servlet</p>

Posted By:   Fabrizio_Marini  
Posted On:   Monday, June 3, 2002 05:35 AM

ResulSet is not Serializable ... try to use RowSet that is part of jdbc2.0 extension pack.
A good way is to use the CachedRowSet ....

Fabrizio Marini

Re: <p>How to return ResultSet type from EJB to Servlet</p>

Posted By:   Dan_Kozin  
Posted On:   Monday, June 3, 2002 12:21 AM

That is a ton of ureadable code!


but I did see some marshalling errors, which most likely means that you have problems with objects that you are trying to pass around. I am not sure, but is ResultSet Serielizable (it has to be to go over RMI). Try putting your result set into a vector and send the vector.


If that doesnt work, please re format your question a little.


dan

Re: <p>How to return ResultSet type from EJB to Servlet</p>

Posted By:   Laurent_Mihalkovic  
Posted On:   Sunday, June 2, 2002 05:08 PM

hi,

I don't know if you tried to read your message after posting it, but when sending sooooo much code, *please*, surround it with some tags... The posting guidelines are just after the text bloc where you typed you text, and they explain clearly how to do it.

thank you for making the task of those who try to help you easier,
laurent

About | Sitemap | Contact