I have to disagree about not throwing the Exception. If you actually
handle the exception in the method then you shouldn't throw it, but
the exception is not being handled. The user needs to know that
something went wrong. And the bit about the Higher scope not importing
the DAOException, that's just plain wrong. The higher scope will see
it as an Exception if it doesn't handle the specific Exception. Not
throwing the exception will simply return an empty list.
The real question is what is the Exception that is being thrown in the
try block? That will tell us what the issue is and lead us to the
conclusion as to how to fix it. Is there a Stack Trace available that
I can look at?
Also...
> > vo.id = rs.getInt("id");
> > vo.data = rs.getString("data");
... this is bad from. You shouldn't be accessing data members
directly, they should be encapsulated, and you should access them
using accesser methods.
Paul
--- In [email protected], "André Rodrigues Pena"
<[EMAIL PROTECTED]> wrote:
>
> Man.. Just remove the throws of your getList() method. Never use
throws at a
> service method. (specially in this example where the throws is USELESS
> because you are already treating the exception with the try clause) The
> throws clause passes the exception treatment to a higher scope, this
scope
> may not import de DAOException needed to process it properly. Simply
never
> do this.
>
> On 2/12/07, ytseshred <[EMAIL PROTECTED]> wrote:
> >
> > I'm using RemoteObjects to connect to my backend. In one of my calls
> > I'm trying to return a List of VO's I create after hitting my
database.
> >
> > On the Flex side, my result event is firing properly, but when I try
> > to convert the result to an ArrayCollection, instead of getting a
> > proper ArrayCollection I get single element that displays the
> > following when I output it in an alert: "obj is: '[object TestVO],
> > [object TestVO], ... [object TestVO]'".
> >
> > If I return a single TestVO object directly instead of a List, I can
> > properly cast the result to my ActionScript TestVO object and view the
> > data properly. It's just returning the List that's giving me problems.
> >
> > Can anyone offer any suggestions please?
> >
> > My Flex result code is:
> >
> > public function result(evt:Object):void {
> > if(evt.type && evt.type == ResultEvent.RESULT) {
> > var re:ResultEvent = evt as ResultEvent;
> > var col:ArrayCollection = new
> > ArrayCollection(ArrayUtil.toArray(re.result));
> > if(col) {
> > Alert.show("obj is: '" + col.getItemAt(0) + "'");
> > }
> > else Alert.show("Didn't cast properly!");
> > }
> > }
> >
> > My Java DAO code that returns the list is:
> >
> > public List getList() throws DAOException {
> > List list = new ArrayList();
> > Connection c = null;
> >
> > try {
> > c = ConnectionHelper.getConnection();
> > Statement s = c.createStatement();
> > ResultSet rs = s.executeQuery("SELECT * FROM test");
> > while(rs.next()) {
> > TestVO vo = new TestVO();
> > vo.id = rs.getInt("id");
> > vo.data = rs.getString("data");
> > list.add(vo);
> > }
> > } catch(Exception e) {
> > e.printStackTrace();
> > throw new DAOException(e);
> > } finally {
> > ConnectionHelper.close(c);
> > }
> > return list;
> > }
> >
> >
> >
>
>
>
> --
> André Rodrigues Pena
>
> LOCUS
> www.locus.com.br
>
> Blog
> www.techbreak.org
>