commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Qin Ding" <>
Subject Re: BeanUtils
Date Thu, 09 Nov 2006 21:01:55 GMT
I modified the JDBCDynaClass.createDynaPropety method.

className = metadata.getColumnClassName(i);
if (className.equals("java.lang.Short")){
    className = "java.lang.Integer";

Now, it works well.  Thank you for the idea.

>>> 11/9/2006 11:03 AM >>>
On 11/9/06, Qin Ding <> wrote:
> in database, 'rqst_sts_cde' is defined as smallint.  I don't know
> these 'Short' or 'Integer' come from.  I guess from build-in
> What is 'smallint' supposed to convert to?  And how to override the
> build-in converter.  Please help.

Digging into the source, it looks like the Short is coming from the
DB2 JDBC driver when BeanUtils asks it what type the DB2 smallint
column should be represented as as a Java object.

Line 169 ot JDBCDynaClass (in trunk):

            className = metadata.getColumnClassName(i);

When BeanUtils then gets the data, it assumes that the object it gets
via ResultSet.getObject (line 232 of RowSetDynaClass) is of the type
that the database is advising it to use. I'm not sure if the JDBC spec
intends for this to be done, but I suspect so.

So I think this is a bug in the DB2 JDBC driver - it's not returning
the type of Object it advises a client to create.

Alfredo has the correct and easiest technical work-around - find a
type that works with the JDBC driver at the database level - 'int'
seems like a good choice. That might be hard to do if you're not in
control of the schema though.

Another work-around would be to extend RowSetDynaClass and override
the copy(ResultSet) method to have a hack to get around this (by
forcing the Integer into a Short when the underlying type is a Short),
or more painfully, overriding createDynaBean() to return a dynabean
that doesn't use Shorts but uses Integers instead. That involves
overriding other methods though.


To unsubscribe, e-mail: 
For additional commands, e-mail: 

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message