Type Handler:
        public Object getResult(ResultGetter getter) throws SQLException {
                if (getter.wasNull())
                        return null;

                java.util.Calendar cal = java.util.Calendar.getInstance();
                java.sql.Timestamp ts = getter.getTimestamp(cal);
 
                cal.setTime(ts);
 
                return cal;
        }

        public void setParameter(ParameterSetter setter, Object parameter)
                        throws SQLException {

                if(parameter == null) {
                        setter.setNull(java.sql.Types.DATE);
                }
                else {
                        java.util.Calendar cal = 
(java.util.Calendar)parameter;
                        setter.setTimestamp(new 
java.sql.Timestamp(cal.getTimeInMillis()), cal);
                }
        }

Result Map:
    <result column="mod_date" jdbcType="TIMESTAMP" property="modifiedDate" 
/>


Don't forget to register the type handler.

I Hope this helps.




"Petr V." <[email protected]> 
01/15/2009 12:13 PM
Please respond to
[email protected]


To
[email protected]
cc

Subject
Java.util.calendar to SQLType ??







Database schema has column of type Timestamp .

Java POJO has corresponding property defined as java.util.Calendar

Result Map is defined as

<resultMap class="Job" id="JobResult">
    <result column="STIME" jdbcType="TIMESTAMP" 
javaType="java.util.Calendar" property="sTime" />
</resultMap>

I understand, I would have to define typeHandler to convert jdbc type to 
java Calendar.

I am wondering what should I define jdbcType is my sql map, should it be 
TimeStamp or should it be of type date. What would be the better?

Thanks,

Petr

Reply via email to