You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by vccarvalho <vc...@bol.com.br> on 2004/08/13 13:52:22 UTC

DynaBeans and ResultSetDynaClass

 Hi there! I'm using dynabeans and resultSetDynaClass to
retreive a resultset from a database. As the sources of
this classes are very rare, I got my self into a
problem. Here's some line of code:


        ResultSetDynaClass rsdc = new
ResultSetDynaClass(rs);
        DynaProperty properties[] =
rsdc.getDynaProperties();
        BasicDynaClass bdc = new
BasicDynaClass("dynaBean", BasicDynaBean.class, properties);
        Iterator it = rsdc.iterator();
        try {
            while (it.hasNext()) {
                DynaBean row = (DynaBean) it.next();
                DynaBean rowCopy = bdc.newInstance();
                PropertyUtils.copyProperties(row, rowCopy);
                results.add(rowCopy);
            }
        }



The SQL statement is the following : "SELECT id_forum,
theme, status FROM forum".

And then I try to use this in this way:


Collection cll = queryRunner.executeDynaQuery(query,
dataSource);
            Iterator it = cll.iterator();
            while(it.hasNext()){
                DynaBean forum = (DynaBean)it.next();
               
System.out.println(forum.get("theme").toString());
            }



But I'm getting a null pointer exception. When I debug,
I noticed that the collection comes with all results
expected (in numbers). The Hashtable inside the object
do have the properties (theme, id_forum and so on) but
they all have null values.
Any ideas????

Thanks a lot

Vinicius Carvalho
 
__________________________________________________________________________
Acabe com aquelas janelinhas que pulam na sua tela.
AntiPop-up UOL - É grátis!
http://antipopup.uol.com.br/



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: DynaBeans and ResultSetDynaClass

Posted by Craig McClanahan <cr...@gmail.com>.
On Fri, 13 Aug 2004 08:52:22 -0300, vccarvalho <vc...@bol.com.br> wrote:
>  Hi there! I'm using dynabeans and resultSetDynaClass to
> retreive a resultset from a database. As the sources of
> this classes are very rare, I got my self into a
> problem. Here's some line of code:

The Javadocs for ResultSetDynaClass have an example of correct usage,
plus the warning that ResultSetDynaClass creates DynaBeans that are
directly attached to the underlying rowset -- it doesn't create copies
of the data.  If you want copies instead (because you want to close
the ReslutSet after doing the query and before using the data), check
out RowSetDynaClass instead.  But, again, you *must* read the JavaDocs
to understand the correct usage.

http://jakarta.apache.org/commons/beanutils/commons-beanutils-1.7.0/docs/api/

Craig

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


RE: DynaBeans and ResultSetDynaClass

Posted by Marco Mistroni <mm...@waersystems.com>.
Hello,
	Can it be this the source of the problem?
        
DynaBean row = (DynaBean) it.next();
DynaBean rowCopy = bdc.newInstance();
PropertyUtils.copyProperties(row, rowCopy);
        
I guess when u use copyProperties the destination come
First, and the source second....

Thus rowcopy does not get populated correctly

Hope this helps

Regards
	marco



-----Original Message-----
From: vccarvalho [mailto:vccarvalho@bol.com.br] 
Sent: 13 August 2004 12:52
To: commons-user
Subject: DynaBeans and ResultSetDynaClass

 Hi there! I'm using dynabeans and resultSetDynaClass to
retreive a resultset from a database. As the sources of
this classes are very rare, I got my self into a
problem. Here's some line of code:


        ResultSetDynaClass rsdc = new
ResultSetDynaClass(rs);
        DynaProperty properties[] =
rsdc.getDynaProperties();
        BasicDynaClass bdc = new
BasicDynaClass("dynaBean", BasicDynaBean.class, properties);
        Iterator it = rsdc.iterator();
        try {
            while (it.hasNext()) {
                DynaBean row = (DynaBean) it.next();
                DynaBean rowCopy = bdc.newInstance();
                PropertyUtils.copyProperties(row, rowCopy);
                results.add(rowCopy);
            }
        }



The SQL statement is the following : "SELECT id_forum,
theme, status FROM forum".

And then I try to use this in this way:


Collection cll = queryRunner.executeDynaQuery(query,
dataSource);
            Iterator it = cll.iterator();
            while(it.hasNext()){
                DynaBean forum = (DynaBean)it.next();
               
System.out.println(forum.get("theme").toString());
            }



But I'm getting a null pointer exception. When I debug,
I noticed that the collection comes with all results
expected (in numbers). The Hashtable inside the object
do have the properties (theme, id_forum and so on) but
they all have null values.
Any ideas????

Thanks a lot

Vinicius Carvalho
 
________________________________________________________________________
__
Acabe com aquelas janelinhas que pulam na sua tela.
AntiPop-up UOL - É grátis!
http://antipopup.uol.com.br/



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org