commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stefan Smeets" <ste...@staf.pi.be>
Subject Re: [BeanUtils] DynaBean and SQL problem
Date Fri, 21 Feb 2003 15:00:35 GMT
could you post the code of the Entity ... declaration and accessor methods ?

grtz

stef



----- Original Message -----
From: <calidris@calidris.f9.co.uk>
To: <commons-user@jakarta.apache.org>
Sent: Friday, February 21, 2003 12:55 PM
Subject: [BeanUtils] DynaBean and SQL problem


>
> I'm trying to use DynaBeans to copy the results of a SQL select into my
bean and it doesn't seem to work.
>
> This code *does* work:
> ----
> PreparedStatement lStatement = lConnection.prepareStatement(
>                                            "select agr_agreement_number as
agreementNumber from agreements WHERE agr_agreement_number = ?");
>       lStatement.setString(1, pAgreementNumber);
>
>       ResultSet lResults = lStatement.executeQuery();
>       lResults.next();
>
>      lAgreement.setAgreementNumber(lResults.getString("agreementNumber"));
> ----
> If I migrate this code to use the Dynabean (I eventually want to select
more columns and auto copy them using copyProperties) I get the following
code:
> ----
>       PreparedStatement lStatement = lConnection.prepareStatement(
>                                            "select agr_agreement_number as
agreementNumber from agreements WHERE agr_agreement_number = ?");
>       lStatement.setString(1, pAgreementNumber);
>
>       ResultSet lResults = lStatement.executeQuery();
>
>       ResultSetDynaClass lResultsSet = new ResultSetDynaClass(lResults);
>       Iterator lRows = lResultsSet.iterator();
>
>       if (lRows.hasNext())
>       {
>         DynaBean lRow = (DynaBean) lRows.next();
>
>         //this.copyProperties(lAgreement, lRow);
>         lAgreement.setAgreementNumber((String)
lRow.get("agreementNumber"));
>       }
> ----
> This does not work, giving me the error:
>
>  java.lang.IllegalArgumentException: agreementNumber
>
> which seems to be from the getting of the property agreementNumber from
the DynaBean.
>
> I'm using BeanUtils 1.6.1, Sun java 1.4.0 on Windows NT, jboss 3.0.4, and
the AgreementNumber is a String.
>
> Is this a bug or am I doing something wrong?
>
> Cheers,
>
> Tim.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>


Mime
View raw message