You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Willem Moors <wi...@gmail.com> on 2010/12/02 07:50:36 UTC

[beanutils] BigDecimal to Double conversion problem in RowSetDynaClass with Oracle's FLOAT datatype

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


[beanutils] BigDecimal to Double conversion problem in RowSetDynaClass with Oracle's FLOAT datatype

Posted by Willem Moors <wi...@gmail.com>.
In case somebody is looking for a solution to problem: here's how I've
solved it.

Create and use a custom RowSetDynaClass in which you put a custom
createDynaProperty() method
(see the original method in RowSetDynaClass's parent JDBCDynaClass).
Following representation has all fluff removed.


public class CustomRowSetDynaClass extends RowSetDynaClass  {
    ..
    // customized method of JDBCDynaClass
    protected DynaProperty createDynaProperty(
            ResultSetMetaData metadata,
            int i)
    throws SQLException {

    ..
        try {
            int sqlType = metadata.getColumnType(i);
            switch (sqlType) {
            case java.sql.Types.DATE:
                ..

            // THIS IS THE CASE TO ADD: oracle FLOAT types are defined
as NUMERIC
            case java.sql.Types.NUMERIC:
                return new DynaProperty(name, java.math.BigDecimal.class);

            ..

            }



---------- Forwarded message ----------
From: Willem Moors <wi...@gmail.com>
Date: Thu, Dec 2, 2010 at 7:50 AM
Subject: [beanutils] BigDecimal to Double conversion problem in
RowSetDynaClass with Oracle's FLOAT datatype
To: user@commons.apache.org


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