これで他の人のブログを見て私も書きます!Object変換別タイプ

1799 ワード

package com.sinitek.framework.util;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Date;

/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: 2011-5-23
* Time: 16:09:26
* To change this template use File | Settings | File Templates.
*/
public class JdbcQueryUtils
{
/**
* Double
* @param object
* @return
*/
public static Double convertToDouble( Object object )
{
if ( object == null )
return null ;

if ( object instanceof BigDecimal )
{
return ( ( BigDecimal )object ).doubleValue( ) ;
}

return null ;
}

/**
* String
* @param object
* @return
*/
public static String convertToString( Object object )
{
if ( object == null )
return null ;

if ( object instanceof String )
{
return object.toString( ) ;
} else {
return String.valueOf(object);
}

}

/**
* Integer
* @param object
* @return
*/
public static Integer convertToInteger( Object object )
{
if ( object == null )
return null ;

if ( object instanceof BigDecimal )
{
return ( ( BigDecimal )object ).intValue( ) ;
}

return null ;
}

/**
* Date
* @param object
* @return
*/
public static Date convertToDate( Object object )
{
if ( object == null )
return null ;

if ( object instanceof Timestamp )
{
return new Date( ( ( Timestamp )object ).getTime( ) ) ;
}

return null ;
}
}