0.事由
在使用Spring Data JPA在数据库中插入记录时,发生了如下错误:
SQL Error: 1366, SQLState: 22001
Data truncation: Incorrect string value: '\xE6\xB5\x8B\xE8' for column `database_name`.`table_name`.`column_name` at row 1
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.DataException: could not execute statement] with root cause
刚开始还以为是数据库连接上出了问题,便尝试使用DataGrip这个数据库管理软件直接插入数据,结果也发生了相同的错误:
Incorrect string value: '\xE6\xB5\x8B\xE8' for column `database_name`.`table_name`.`column_name` at row 1
显然,这是数据库本身的字符集导致的问题了。
1.修改数据库字符集
ALTER DATABASE database_na