项目环境:springboot 2.1.4.RELEASE+mybatisplu 3.1.1 + 数据源两个mysql和sqlserver.
报错内容:
org.springframework.dao.DataIntegrityViolationException:Error attempting to get column 'open_date' from result set.
Cause: com.microsoft.sqlserver.jdbc.SQLServerException: The conversion to class java.time.LocalDateTime is unsupported.
; The conversion to class java.time.LocalDateTime is unsupported.; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: The conversion to class java.time.LocalDateTime is unsupported.at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:104)
今天在做多数据源操作的时候,读取sqlserver的时候,报以上错误。大致意思为:sqlserver类型转换异常,不支持LocalDateTime
第一反应是有两个可能,MP版本,sqlserver版本,MP3.X不应该出现在这问题,于是看了看sql版本,下面应该是我创建项目时自动生成的
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>runtime</scope>
<version>6.4.0.jre8</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
<scope>test</scope>
</dependency>
重点在第一个,查了下,如下图,这时间,感人。。。
于是换成了这个。 后面的.jreX就是你的jre版本,用错会提示jre版本不对
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>8.4.1.jre8</version>
</dependency>
启动,运行 OK!
BTW, 如果用mybatis的,替换之后还不行的话,检查mybatis版本,改成3.5以下的版本就可以了
点关注,不迷路,不定时更新。。