I have a text area on the site where the user can write anything. The problem occurs when the user copies some text or something that contains non-UTF 8 characters and sends them to the server.
Java handles it successfully because it supports UTF-16, but my mySql table supports UTF-8 and therefore the insertion fails.
I tried to somehow implement in the business logic itself to remove any characters that are not suitable for UTF-8 encoding.
I am currently using this code:
new String(java.nio.charset.Charset.forName("UTF-8").encode(myString).array());
But it replaces characters that are not suitable for UTF-8, with some other obscure characters. Which is also not suitable for the end user. Can anyone comment on any possible solution to this problem using Java code?
EDIT: For example, the exception I received while inserting such values
java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x8A\x0D\x0A...' for column java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x80\xF0\x9F...' for column
source share