oracle驱动中的getDate只返回日期,没有时间,而getTimestamp返回日期和时间。
由于特殊原因,我不是根据字段类型来获取值,而是以Object方式获取字段值,结果是取不到时间,
研究ibatis源码,
发现DateTypeHandler.java中已经做了转换,使用getTimestamp获取值再转成Date,但是ObjectTypeHandler却没做转换,而程序却是调用ObjectTypeHandler,所以出现取不到时间的问题,于是修改ObjectTypeHandler源码,增加
boolean b = object instanceof java.sql.Date;
if (b)
object = new Date(rs.getTimestamp(columnName).getTime());
,然后把class放到jar中就好了
修改com.ibatis.sqlmap.engine.type.ObjectTypeHandler
public Object getResult(ResultSet rs, String columnName)
throws SQLException
{
Object object = rs.getObject(columnName);
if (rs.wasNull())
{
return null;
}
else
{
boolean b = object instanceof java.sql.Date;
if (b)
object = new Date(rs.getTimestamp(columnName).getTime());
return object;
}
}
public Object getResult(ResultSet rs, int columnIndex) throws SQLException
{
Object object = rs.getObject(columnIndex);
if (rs.wasNull())
{
return null;
}
else
{
boolean b = object instanceof java.sql.Date;
if (b)
object = new Date(rs.getTimestamp(columnIndex).getTime());
return object;
}
}
public Object getResult(CallableStatement cs, int columnIndex)
throws SQLException
{
Object object = cs.getObject(columnIndex);
if (cs.wasNull())
{
return null;
}
else
{
boolean b = object instanceof java.sql.Date;
if (b)
object = new Date(cs.getTimestamp(columnIndex).getTime());
return object;
}
}