Discussions

EJB programming & troubleshooting: problem while returning resultset

  1. problem while returning resultset (2 messages)

    Hi,

    I am working on a stateless session bean which has two methods.The first method will take in a query string and execute it and returns the number of rows inserted,updated and deleted.This works fine.

    The second method again recieves a query string and returns a resultset.Here is the code,

    public java.sql.ResultSet read(String query) throws RemoteException,SQLException
    {
    this.query=query;
    this.nameOfDB=nameOfDB;
    java.sql.Connection conn=null;
    java.sql.Statement stmt=null;
    java.sql.ResultSet rs=null;
    try
    {
    this.query=query;
    conn=this.getConnection(nameOfDB);
    stmt=conn.createStatement();
    rs=(java.sql.ResultSet)stmt.executeQuery(query);
    }
    catch(SQLException e)
    {
    System.out.println("ERROR"+e);
    }
    catch(Exception se)
    {
    System.out.println("Error"+ se);
    }
    System.out.println("Before Resultset" );
    return (java.sql.ResultSet)rs;

    }

    When i print the resultset it gives me all the values for the query on the server i use weblogic 5.1 application server.

    The problem is whenever a client accesses this method it throws a ClassCastException.The stack trace it prints is


    java.lang.ClassCastException: weblogic.jdbc20.rmi.internal.ResultSetStub

    java.lang.ClassCastException: weblogic.jdbc20.rmi.internal.ResultSetStub

    at weblogic.jdbc20.rmi.SerialResultSet.readObject(SerialResultSet.java:1679)

    at weblogic.common.internal.WLObjectInputStreamBase.readPublicSerializable(WLObjectInputStreamBase.java:265)

    at weblogic.common.internal.WLObjectInputStreamBase.readLeftover(WLObjectInputStreamBase.java:254)

    at weblogic.common.internal.WLObjectInputStreamBase.readObjectBody(WLObjectInputStreamBase.java:202)

    at weblogic.common.internal.WLObjectInputStreamBase.readObject(WLObjectInputStreamBase.java:949)

    at weblogic.common.internal.WLObjectInputStreamBase.readObjectWL(WLObjectInputStreamBase.java:308)

    at weblogic.rmi.extensions.AbstractInputStream2.readObject(AbstractInputStream2.java:25)

    at com.iPlexus.BaseDL.ConnectionPoolBeanEOImpl_WLStub.read(ConnectionPoolBeanEOImpl_WLStub.java:285)

    at com.iPlexus.BaseDL.ConnectionPoolBeanEOImpl_ServiceStub.read(ConnectionPoolBeanEOImpl_ServiceStub.java, Compiled Code)

    at hello.go(hello.java:32)

    at hello.main(hello.java:70)


    The error is on the client side and the server prints the resultset.There is an error while dispatching the resutlset.


    One funny thing,this bean was working fine i modified it and put some SOP's in between and from then it is not working.

    Thanks,
    Santosh



  2. problem while returning resultset[ Go to top ]

    Perhaps ResultSet is not serializable, and so cannot
    be sent to the client via RMI. Instead of returning
    a ResultSet, why not place the data into a serializable
    object and return that instead (Tom Valesky's "Enterprise Java Beans" does this with an InventoryItem; talks alittle about Serializable on p. 84).

    No idea why it worked for you before the SOPs.

    -Marc
  3. problem while returning resultset[ Go to top ]

    why dont u use? vector for returning the result to the client as its serializeable.
    i also had classcast exception. the reason for thats was that i had some older versions of that file as well in the same package so it tried to cast it with the older version but the implementation is according to the newer version so try to remove all unnecessary files from ur package