commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From calid...@calidris.f9.co.uk
Subject [BeanUtils] DynaBean and SQL problem
Date Fri, 21 Feb 2003 11:55:17 GMT

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.


Mime
View raw message