我想使用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類型? –