体现:

hibernate插入数据时,一直报错:

Caused by: java.sql.SQLException: Incorrect string value: '\xE5\xBC\xA0\xE4\xB8\x89' for column 'nam

导致原因就是数据库和数据表的编码方式导致的。

解决方案:

尝试将数据库以及数据表的编码方式改为UTF-8

hibernate插入中文字段时,无法插入数据库

在Hibernate中建议在配置文件hibernate.cfg.xml中添加:

<!-- 设置编码方式为utf-8 -->  
<property name="hibernate.connection.characterEncoding">utf-8</property>
<!-- 是否根据需要自动建表 -->
<property name="hbm2ddl.auto">update</property>

这样的话以后我们再自动建表时就会自动将排序规则设置为utf-8.
重新执行以下就好了。

 

相关文章:

  • 2022-12-23
  • 2021-09-23
  • 2022-02-24
  • 2021-10-17
  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-31
  • 2021-11-08
  • 2021-09-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案