org.springframework.dao.TypeMismatchDataAccessException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • 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.
    via by Ian Brandt,
  • 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.
    via by 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] 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)
    No Bugmate found.