“Incorrect string value” when trying to insert UTF-8 into MySQL via JDBC?

前端 未结 18 1150
无人及你
无人及你 2020-11-22 07:51

This is how my connection is set:
Connection conn = DriverManager.getConnection(url + dbName + \"?useUnicode=true&characterEncoding=utf-8\", userName, password

18条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 08:01

    If you are creating a new MySQL table, you can specify the charset of all columns upon creation, and that fixed the issue for me.

    CREATE TABLE tablename (
    
    )
    CHARSET SET utf8mb4 COLLATE utf8mb4_unicode_ci;
    

    You can read more details: https://dev.mysql.com/doc/refman/8.0/en/charset-column.html

提交回复
热议问题