Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-4886

Problem extracting Oracle Timestamp with SQLRowset

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: 2.5.3
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      I extract data from an Oracle Database using org.springframework.jdbc.core.JdbcTemplate.

      If I try to extract data from timestamp columns, I get a ClassCastException, because the template gets an oracle.sql.TIMESTAMP object instead of a java.sql.Timestamp.

      SqlRowSet rs = _jdbcTemplate.queryForRowSet("SELECT FFNACPER FROM TEMP_ALPER");
      rs.next();
      java.sql.Timestamp timestamp = rs.getTimestamp("FFNACPER"); //HERE I GET A CLASSCASTEXCEPTION

      To make it work, I must get an object, and convert it manually:

      oracle.sql.TIMESTAMP timestamp = (oracle.sql.TIMESTAMP) rs.getObject("FFNACPER");
      return (timestamp == null) ? null : new Date(timestamp.dateValue().getTime());

      It also works ok, if I use a ResultSetExtractor instead of an SqlRowSet

      _jdbcTemplate.query("SELECT FFNACPER FROM TEMP_ALPER", new ResultSetExtractor(){
      public Object extractData(ResultSet rs) throws SQLException, DataAccessException

      { rs.next(); Timestamp t = rs.getTimestamp("FFNACPER"); //WORKS OK return t; }


      } );

      Have tested only for timestamp. Haven't tried with rs.getDate, or rs.getTime

        Attachments

          Activity

            People

            • Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              rober2d2 Roberto Ruiz
              Last updater:
              Juergen Hoeller
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                2 years, 43 weeks, 5 days ago