我想使用Spring-JPA更新列的值,值是表情符号/表情符号。 但得到错误说java.sql.BatchUpdateException:不正确的字符串值: '\ XF0 \ x9F \ X98 \ X84 \ XF0 \ x9F ......' 对于com.mysql.jdbc.MysqlDataTruncation:数据截断:数据太长的列'aboutMeText'在第1行
列这里是连接URL-
jdbc.url=jdbc:mysql:localhost:3306/woo?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&connectionCollation=utf8mb4_unicode_ci&characterSetResults=UTF-8
下面是调用代码
userProfile.setAboutMeText("\uD83D\uDE04\uD83D\uDC68\u200D\u2764\uFE0F\u200D\uD83D\uDC8B\u200D\uD83D\uDC68\uD83D\uDE02\uD83D\uDE20");
这里是实体
@Entity
public class UserProfile implements Serializable {
@Column(length = 1000)
private String aboutMeText;
@Id
private Long id;
public Long getId() {
return id;
}
public void seId(Long id) {
this.id = id;
}
public String getAboutMeText() {
return JsonEscape.unescapeJson(aboutMeText);
}
public void setAboutMeText(String aboutMeText) {
this.aboutMeText = JsonEscape.escapeJson(aboutMeText);
}
和
这里是完整的错误:
HTTP Status 500 - Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: Data truncation: Data too long for column 'aboutMeText' at row 1; SQL [n/a]; nested exception is org.hibernate.exception.DataException: Data truncation: Data too long for column 'aboutMeText' at row 1</h1>
<div class="line"></div>
<p>
<b>type</b> Exception report
</p>
<pre>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: Data truncation: Data too long for column 'aboutMeText' at row 1; SQL [n/a]; nested exception is org.hibernate.exception.DataException: Data truncation: Data too long for column 'aboutMeText' at row 1
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:981)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
我尝试和检查了计算器,stackexchange等各个岗位..和执行了一些变化,但仍无法解决问题。
将排序规则更改为utf8_unicode_ci ... [检查此](http://stackoverflow.com/a/20431999/4117061)和[this](http://stackoverflow.com/a/10959780/4117061) –
previous它是utf8_unicode_ci,但我得到相同的错误,所以将其改为utf8mb4_unicode_ci –
它是一个二进制数据,你正在存储在该列?那么它不应该是字节[]而不是字符串blob类型? –