commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rafael U. C. Afonso" <>
Subject [BeanUtils]SqlDateConverter: Better implmentation.
Date Fri, 06 Aug 2004 02:14:31 GMT

I read the code of SqlDateConverter.convert(). It is 
implmented in this form:

        if (value == null) {
            if (useDefault) {
                return (defaultValue);
            } else {
                throw new ConversionException("No value 

        if (value instanceof Date) { // java.sql.Date
            return (value);

        try {
            return (Date.valueOf(value.toString()));
        } catch (Exception e) {
            if (useDefault) {
                return (defaultValue);
            } else {
                throw new ConversionException(e);

About null values, I understand. My question is about case if 
value is not a java.sql.Date. It could be a java.util.Date or 
a other subclass (not java.sql.Date). IMHO a more acurate 
algoritm could be this:

// same procedure if value is null

        if (value instanceof java.sql.Date) { // java.sql.Date
            return (value);
        if (value instanceof java.utilDate) { // java.sql.Date
            return new java.sql.Date(((java.util.Date)
// same procedure if value is not a java.util.Date

Some thing similar could be done with SqlTimeConverter and 
If you do not agree this alternative I would like know the 


Rafael Ubiratam Clemente Afonso
Where is Debug?
Debug is on the Table!
Acabe com aquelas janelinhas que pulam na sua tela.
AntiPop-up UOL - É grátis!

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

View raw message