Programming and So

Tips and tricks in Java

Oracle JDBC Driver and Spring 2.0.X Timestamp issue

leave a comment »

Oracle JDBC Driver (ojdbc14.jar)

Spring Framework 2.0

import org.springframework.jdbc.support.rowset.SqlRowSet;

public class QueryDAO extends JdbcDaoSupport {

    public SqlRowSet loadSqlRowSet(String sSQL) {
        return getJdbcTemplate().queryForRowSet(sSQL);
    }

}

Using Spring JDBC in such way Timestamp fields are recovered without time information (hours, minutes and seconds set to 0). It seems some issue relative to Sun or Oracle, but there is a workaround in order to achieve desired result.

SqlRowSet rset =
    jdbcTemplate.queryForRowSet("select cast(sysdate as timestamp) from dual");
while (rset.next()) {
    System.out.println("-> " +
        ((oracle.sql.TIMESTAMP)rset.getObject(1)).timestampValue());
}

Our batch process failed last night because of this…

Written by angelborroy

April 30, 2009 at 2:33 pm

Posted in java

Tagged with , ,

Leave a Reply