how to get a result set back from the session bean in db access


EJB design: how to get a result set back from the session bean in db access

  1. hai everybody,

    i want to return all the records(i.e) after getting a resultset to be returned from the bean(i.e

    public ResultSet getRecords()

    i am getting a error called when i invoke this from client:

    ResultSet rs = Rinterf.getRecords();

    the error message is:
    weblogic .jdbc20.rmi.internal.ResultSetStub

    with regards
  2. This is not possible as ResultSet is not Serializable hence can't be transfered to client from Session Bean.
  3. A simple solution would be:

    Create a Serializable class that mimics the structure of the data you wish to return (I'll call this a 'data object'). Then, in the session bean, iterate through the resultset, instantiate a copy of the 'data object', set its attributes based on those of the resultset (or more simply, create a constructor that takes the current row of the resultset and populates its own attributes in te constructor), add it to a collection or arraylist, finally when all desired records are read/populated, return the collection object.

    This has worked for me on many occasions.

  4. Another better solution is to use an IDL implementation of a ResultSet. This would be both serializable as well as marshallable over RMI/IIOP as an IDL type. See my pattern for an overall review.

    In Sybase EAServer we ship just such an IDL type as well as static methods to convert from a java.sql.ResultSet into the IDL type for marshalling, and back to the java.sql.ResultSet.

    My team is currently working on porting the conversion routines over to open source.

    The advantage is interoperability via CORBA, faster marshalling then serialized types yet still works in basic RMI implementations.

    See the patterns section for a brief overview.

    Dave Wolf
    Internet Applications Division
  5. I'm a bit of a newbie to all this, but i reckon you could also use this rowset thing from sun

    (you need to register with them tho)

    "A disconnected RowSet object, such as a CachedRowSet object or a WebRowSet object, can be thought of as a set of rows that are being cached outside of a data source. Because they are lightweight and serializable, disconnected rowsets can be passed between different components of a distributed application, such as Enterprise JavaBeansTM components. This is one of the most important uses for a RowSet object. The data in a RowSet object may be updated and then resynchronized with the underlying tabular data source."

    I use it and it works nicely

    Take it easy