Fabrice,

Thanks for the reply.  However, the javadocs on the CachedRowSet
specifically state that the toCollection() method return a collection, not a
TreeMap.  This is where I am confused.  I realize that the a TreeMap is not
a collection as you state, but the method should be returning a Collection;
or am I reading the javadoc incorrectly?  I'm not really sure where the
TreeMap cast exception is coming from, looks like an issue in the
CachedRowSet object base on the line number of the error in the exception.

I tried casting the crs.toCollection to a TreeMap, but the same exception is
generated:

java.lang.ClassCastException: java.util.TreeMap
        at sun.jdbc.rowset.CachedRowSet.toCollection(CachedRowSet.java:1057)

        TreeMap myTreeMap;

        try {
                crs.execute();
                crs.first();
                myTreeMap = (TreeMap)crs.toCollection();
        }

Any other ideas?

Thanks in advance.

Regards,

Todd

-----Original Message-----
From: Fabrice Valois [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 06, 2001 8:04 AM
To: [EMAIL PROTECTED]
Subject: Re: CachedRowSet - how to convert to a collection with the
"toCol lect ion()" method


TreeMap isn't a Collection but a Map. 
You can't cast it into a Collection ! 

If you really want a collection from a TreeMap, you have to choice either
the keySet
or the entrySet of the TreeMap.

fv

-----Message d'origine-----
De : Todd G. Nist [mailto:[EMAIL PROTECTED]]
Envoy� : jeudi 6 d�cembre 2001 13:58
� : [EMAIL PROTECTED]
Objet : CachedRowSet - how to convert to a collection with the
"toCollect ion()" method


Hello,

I must be missing something simple here, but here is the question.

I have a servlet which is generating a CachedRowSet for holding the data for
processing by a JSP.  The jsp is using the struts tags, specifically, the
"logic:iterator" tag which requires a Collection of one of the following
types:

    array, java.util.Collection, ArrayList, Vector, juaa.util.Enumeration,
iterator, HashMap, Hastable or TreeMap.

There is a tag on the CachedRowSet called "toCollection()" which according
to the documentation returns a "java.util.Collection".  When ever I try to
convert it to a collection with the above method, I receive the following
error:

java.lang.ClassCastException: java.util.TreeMap
at sun.jdbc.rowset.CachedRowSet.toCollection(CachedRowSet.java:1057)

The basic code fragment which throws the exception looks like this:

        Collection myCollection = null;
        CachedRowSet crs = null;
        // do necessary setup and obtain valid CachedRowSet;
        try{
                crs.execute(getCon());
                crs.first();
                myCollection = crs.toCollection();
        }
        .
        .
        .

So the question is how to I manage to convert the CachedRowSet to one of the
above collections.

Regards,

Todd G. Nist
Email:   [EMAIL PROTECTED]

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html


-------------------------------------------------------------
This Message and any attachments are confidential and intended
solely for the addressees. And unauthorised use or dissemination 
are prohibited. Emails are suceptible to alteration. Therefore 
neither SWAPCOM nor any of its subsidiaries or affiliates shall 
be liable for the message if altered, changed or falsified.  

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to