Java 使用Spring JPA将阿拉伯语文本保存到mysql

Java 使用Spring JPA将阿拉伯语文本保存到mysql,java,mysql,spring,hibernate,jpa,Java,Mysql,Spring,Hibernate,Jpa,大家好,我的应用程序基于SpringMVC,我试图在MySQL中保存阿拉伯语文本(我使用JPA),但它保存的是??而不是阿拉伯语字符。我试着用这个: spring.datasource.url=jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8 但我在尝试用阿拉伯语保存文本时出错: java.sql.SQLException: Incorrec

大家好,我的应用程序基于SpringMVC,我试图在MySQL中保存阿拉伯语文本(我使用JPA),但它保存的是??而不是阿拉伯语字符。我试着用这个:

spring.datasource.url=jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8
但我在尝试用阿拉伯语保存文本时出错:

java.sql.SQLException: Incorrect string value: '\xD8\xAA\xD8\xB1\xD8\xAD...' for column 'last_name' at row 1

提前感谢。

您好,在互联网上搜索了一会儿之后,我在application.properties中添加了几行代码,以便使用UTF-8编码,最终成功了。这是文件。不要忘记更改url和密码等

   # DataSource settings: set here your own configurations for the   
# #database 
    # connection. In this example we have "netgloo_blog" as database name #and 
    # "root" as username and password.
    spring.datasource.url = jdbc:mysql://localhost:3306/newDB?useUnicode=yes&characterEncoding=UTF-8&characterSetResults=UTF-8
    spring.datasource.username = root
    spring.datasource.password = somePassword

    # Keep the connection alive if idle for a long time (needed in #production)
    spring.datasource.testWhileIdle = true
    spring.datasource.validationQuery = SELECT 1

    # Show or not log for each sql query
    spring.jpa.show-sql = true

    # Hibernate ddl auto (create, create-drop, update)
    spring.jpa.hibernate.ddl-auto = update
    server.tomcat.uri-encoding=UTF-8

    # HTTP encoding (HttpEncodingProperties)
    spring.http.encoding.charset=UTF-8
    spring.http.encoding.enabled=true
    spring.http.encoding.force=true

    # Naming strategy
    spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy

    # Use spring.jpa.properties.* for Hibernate native properties (the #prefix is
    # stripped before adding them to the entity manager)

    # The SQL dialect makes Hibernate generate better SQL for the chosen #database
    spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
    spring.jpa.properties.hibernate.connection.characterEncoding=utf-8
    spring.jpa.properties.hibernate.connection.CharSet=utf-8
    spring.jpa.properties.hibernate.connection.useUnicode=true

    server.port=8080

将表格集合更改为utf8\u general\u ci。它应该可以工作。。您好,谢谢您的回答。我检查并发现我的MySQL使用utf8mb4编码,所以我通过将默认编码设置为utf8_unicode来配置MySQL,从而解决了这个问题。