Question

I've setup spring boot so under /health to display the datasource status. However, I'm getting this JSON back:

"dataSource" : {
   "status" : "DOWN",
   "database" : "MySQL",
   "error" : "org.springframework.dao.TransientDataAccessResourceException: StatementCallback; SQL [SELECT 1]; Conversion not supported for type java.lang.Object; nested exception is java.sql.SQLException: Conversion not supported for type java.lang.Object"
},

As you can see my database is mysql and I'm running it on Windows8. I did try the 'select 1' query and it did return 1 in the command line of mysql. Any idea where the problem might be?

Était-ce utile?

La solution

DataSourceHealthIndicator runs its configured query (SELECT 1 by default) by calling JdbcTemplate:

this.jdbcTemplate.queryForObject(query, Object.class)

On Java 6, this ultimately leads to a call to ResultSet.getObject(index) and things work as expected. On Java 7, the call is to ResultSet.getObject(index, Object.class) (this overload of getObject is new in Java 7). In its default configuration the MySQL JDBC driver is unable to create and return an instance of java.lang.Object so it throws the exception described in the question.

You can change MySQL's behaviour and have it return an instance of whatever is appropriate for the column by enabling auto-deserialization:

spring.datasource.url: jdbc:mysql://localhost/test?autoDeserialize=true

I've also opened Spring boot issue so that we can make a change so that enabling auto-deserialization isn't necessary.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top