commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Willem Moors <willem.mo...@gmail.com>
Subject [beanutils] BigDecimal to Double conversion problem in RowSetDynaClass with Oracle's FLOAT datatype
Date Thu, 02 Dec 2010 06:50:36 GMT
Hi,

When using RowSetDynaClass of BeanUtils to read a data from a table
containing a "FLOAT", I get following exception:
ConversionException: Cannot assign value of type
'java.math.BigDecimal' to property 'value' of type 'java.lang.Double'
The database in question is Oracle 10.

Here's a detailed description. First case shows that it does work for
the regular NUMBER datatype, the second case shows it doesn't work for
the FLOAT datatype.

-----
1) In sqlplus:
create table wm_test( id int, value number) ;
insert into wm_test values(1, 123.24 ) ;


In my java code: "Select * from wm_test"
id  value
-- ------
 1 123.24


-----
2) In sqlplus:
drop table wm_test;
create table wm_test( id int, value float) ;
insert into wm_test values(1, 123.24 ) ;


In my java code: "Select * from wm_test"

Exception in thread "main"
org.apache.commons.beanutils.ConversionException: Cannot assign value
of type 'java.math.BigDecimal' to property 'value' of type
'java.lang.Double'

        at org.apache.commons.beanutils.BasicDynaBean.set(BasicDynaBean.java:305)
        at org.apache.commons.beanutils.RowSetDynaClass.copy(RowSetDynaClass.java:294)
        at org.apache.commons.beanutils.RowSetDynaClass.<init>(RowSetDynaClass.java:248)
        at org.apache.commons.beanutils.RowSetDynaClass.<init>(RowSetDynaClass.java:181)
        at org.apache.commons.beanutils.RowSetDynaClass.<init>(RowSetDynaClass.java:105)
        at ccl.common.StandardService.getRowSetDynaClass(StandardService.java:72)
        at ccl.action.SQL.doSQL(SQL.java:63)
        at ccl.Main.doExecute(Main.java:93)
        at ccl.Main.main(Main.java:27)


Here's the code that retrieves the result:
        public List getRowSetDynaClass( Connection connection, String sql)
        throws SQLException
        {
                PreparedStatement pstmt= connection.prepareCall( sql );
                ResultSet resultSet=pstmt.executeQuery();

                RowSetDynaClass rsdc = new RowSetDynaClass(resultSet);
                resultSet.close();
                pstmt.close();
                return rsdc.getRows();
        }

What needs to be done to solve this ?

Ciao,

Willem

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


Mime
View raw message