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

前端 未结 18 1118
无人及你
无人及你 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

    The strings that contain \xF0 are simply characters encoded as multiple bytes using UTF-8.

    Although your collation is set to utf8_general_ci, I suspect that the character encoding of the database, table or even column may be different. They are independent settings. Try:

    ALTER TABLE database.table MODIFY COLUMN col VARCHAR(255)  
        CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;
    

    Substitute whatever your actual data type is for VARCHAR(255)

提交回复
热议问题