【问题标题】:Hibernate mysql utf8 configuration休眠mysql utf8配置
【发布时间】:2017-03-04 16:38:56
【问题描述】:

我使用的是休眠 4.1.4,mysql 连接器是 5.1.6。 Hibernate 和 tomcat server.xml 连接器配置如下。当我尝试保存时,我得到了那个例外。怎么了?

Caused by: java.sql.SQLException: Incorrect string value: '\xC5\x9Fekk\xC3...'

<Connector port="8080" maxHttpHeaderSize="8192"
           maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
           enableLookups="false" redirectPort="8443" acceptCount="100"
           connectionTimeout="20000" disableUploadTimeout="true"
           URIEncoding="UTF-8" />

<hibernate-configuration> <session-factory> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost/*****?UseUnicode=true&amp;characterEncoding=utf8</property> <property name="hibernate.connection.CharSet">utf8</property> <property name="hibernate.connection.characterEncoding">utf8</property> <property name="hibernate.connection.useUnicode">true</property> <property name="hibernate.connection.username">****</property> <property name="hibernate.connection.password">***</property> <property name="hibernate.hbm2ddl.auto">update</property> </session-factory> </hibernate-configuration>

【问题讨论】:

  • 什么是 ***** 值??
  • 这是我的数据库名称、用户名和密码。 @Mahi 没问题
  • 在连接 url 中尝试 utf-8
  • 连接 url 也有 utf-8 是不是错了? jdbc:mysql://localhost/whatever?UseUnicode=true&amp;amp;characterEncoding=utf8&lt;
  • 用 utf8 代替 utf-8

标签: mysql spring hibernate utf-8


【解决方案1】:

十六进制 C58F 在 utf8/utf8mb4 编码中是 ş

在 Hibernate 配置中,我认为它是用破折号拼写的:UTF-8

另见https://docs.jboss.org/exojcr/1.12.13-GA/developer/en-US/html/ch-db-configuration-hibernate.html

【讨论】:

    猜你喜欢
    • 2012-11-19
    • 1970-01-01
    • 1970-01-01
    • 2010-11-08
    • 1970-01-01
    • 2015-07-28
    • 2016-05-06
    • 2018-10-21
    • 2011-01-05
    相关资源
    最近更新 更多