首页 > 技术文章 > Cause: java.sql.SQLException: Unknown initial character set index '255' received from server. Initial client character set can be forced via the 'characterEncoding' property.

wongzzh 2021-08-17 10:38 原文

报错信息:

### Error querying database.  Cause: java.sql.SQLException: 
Unknown initial character set index '255' received from server. Initial client character set can be forced via the 'characterEncoding' property. ### The error may exist in com/dy/dao/mapping/userDao-mapping.xml ### The error may involve com.dy.dao.UserDao.findUserById ### The error occurred while executing a query ### Cause: java.sql.SQLException: Unknown initial character set index '255' received from server.
Initial client character set can be forced via the 'characterEncoding' property.
 

错误原因:

驱动与数据库字符集不匹配

mysql  数据库版本是 mysql-8.0.23-winx64

驱动是: 

<dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.12</version>
</dependency>

解决方式一:

1.在url中添加字符集说明

"jdbc:mysql://localhost:3306/mybatis?characterEncoding=utf8"

2、换一个新版本的mysql-connector-java

<dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.44</version>
</dependency>

  

 

推荐阅读