org.springframework.dao.TypeMismatchDataAccessException: Type mismatch affecting row number 0 and column type 'NUMBER': Value [2] is of type [java.lang.Integer] and cannot be converted to required type [int]

Spring JIRA | Ian Brandt | 3 years ago
  1. 0

    I'm not sure if this is a documentation issue, a bug, or a driver specific nuance, but when I use {{queryForObject}} as shown in the [reference manual|http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/jdbc.html#jdbc-JdbcTemplate-examples] I get a {{TypeMismatchDataAccessException}}: {code:java} int rowCount = this.jdbcTemplate.queryForObject("select count(*) from t_actor", int.class); {code} {noformat} org.springframework.dao.TypeMismatchDataAccessException: Type mismatch affecting row number 0 and column type 'NUMBER': Value [2] is of type [java.lang.Integer] and cannot be converted to required type [int] at org.springframework.jdbc.core.SingleColumnRowMapper.mapRow(SingleColumnRowMapper.java:98) at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:92) at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:60) at org.springframework.jdbc.core.JdbcTemplate$1QueryStatementCallback.doInStatement(JdbcTemplate.java:446) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:396) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:456) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:464) at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:472) at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:477) {noformat} The workaround is to use {{Integer.class}} instead of {{int.class}} as the type parameter: {code:java} int rowCount = this.jdbcTemplate.queryForObject("select count(*) from t_actor", Integer.class); {code} Database is Oracle 10.2.0.5 with JDBC driver 11.2.0.3.

    Spring JIRA | 3 years ago | Ian Brandt
    org.springframework.dao.TypeMismatchDataAccessException: Type mismatch affecting row number 0 and column type 'NUMBER': Value [2] is of type [java.lang.Integer] and cannot be converted to required type [int]
  2. 0

    I'm not sure if this is a documentation issue, a bug, or a driver specific nuance, but when I use {{queryForObject}} as shown in the [reference manual|http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/jdbc.html#jdbc-JdbcTemplate-examples] I get a {{TypeMismatchDataAccessException}}: {code:java} int rowCount = this.jdbcTemplate.queryForObject("select count(*) from t_actor", int.class); {code} {noformat} org.springframework.dao.TypeMismatchDataAccessException: Type mismatch affecting row number 0 and column type 'NUMBER': Value [2] is of type [java.lang.Integer] and cannot be converted to required type [int] at org.springframework.jdbc.core.SingleColumnRowMapper.mapRow(SingleColumnRowMapper.java:98) at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:92) at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:60) at org.springframework.jdbc.core.JdbcTemplate$1QueryStatementCallback.doInStatement(JdbcTemplate.java:446) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:396) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:456) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:464) at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:472) at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:477) {noformat} The workaround is to use {{Integer.class}} instead of {{int.class}} as the type parameter: {code:java} int rowCount = this.jdbcTemplate.queryForObject("select count(*) from t_actor", Integer.class); {code} Database is Oracle 10.2.0.5 with JDBC driver 11.2.0.3.

    Spring JIRA | 3 years ago | Ian Brandt
    org.springframework.dao.TypeMismatchDataAccessException: Type mismatch affecting row number 0 and column type 'NUMBER': Value [2] is of type [java.lang.Integer] and cannot be converted to required type [int]

    Root Cause Analysis

    1. org.springframework.dao.TypeMismatchDataAccessException

      Type mismatch affecting row number 0 and column type 'NUMBER': Value [2] is of type [java.lang.Integer] and cannot be converted to required type [int]

      at org.springframework.jdbc.core.SingleColumnRowMapper.mapRow()
    2. Spring Framework
      JdbcTemplate.queryForObject
      1. org.springframework.jdbc.core.SingleColumnRowMapper.mapRow(SingleColumnRowMapper.java:98)
      2. org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:92)
      3. org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:60)
      4. org.springframework.jdbc.core.JdbcTemplate$1QueryStatementCallback.doInStatement(JdbcTemplate.java:446)
      5. org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:396)
      6. org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:456)
      7. org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:464)
      8. org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:472)
      9. org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:477)
      9 frames