Uploaded image for project: 'Spring Data JDBC'
  1. Spring Data JDBC
  2. DATAJDBC-15

Incorrect output of big numbers when using NamedParameterJdbcTemplate.queryForLong

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 1.0 M2, 1.0 RC1, 1.0 RELEASE
    • Fix Version/s: None
    • Component/s: JDBC
    • Labels:
      None
    • Environment:
      detected against Oracle 11g DB

      Description

      In a table column we use 19-digit IDs. The column type is set to NUMBER. An example of an ID is "1000000009704976470". Now, if we access by using NamedParameterJdbcTemplate.queryForLong (String sql, SqlParameterSource paramSource) or overloaded methods, it returns the for example the long 1000000009704976512L instead of "1000000009704976470". The cause lies in the implementation of the method queryForLong.

      The current implementation looks like this:
      public long queryForLong(String sql, SqlParameterSource paramSource) throws DataAccessException {
      Number number = queryForObject(sql, paramSource, Number.class);
      return (number != null ? number.longValue() : 0);
      }

      A solution could look like this:
      public long queryForLong(String sql, SqlParameterSource paramSource) throws DataAccessException {
      Number number = queryForObject(sql, paramSource, Long.class);
      return (number != null ? number.longValue() : 0);
      }

      One more note, the JdbcTemplate class implements the method queryForLong properly.

        Issue Links

          Activity

          Hide
          andre.rouel André Rouél added a comment -

          This is not the correct project. The issue moved to SPR-8652.

          Show
          andre.rouel André Rouél added a comment - This is not the correct project. The issue moved to SPR-8652 .

            People

            • Assignee:
              thomas.risberg Thomas Risberg
              Reporter:
              andre.rouel André Rouél
              Last updater:
              Trevor Marshall
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: