I have a text-area on website where user can write anything. Problem happens when user copy paste some text or something which contains non-UTF 8 characters and submit them to server.
Java successfully handles it, as it support UTF-16 but my mySql table support UTF-8 and thus insertion fails.
I was trying to implement some way in business logic itself, to remove any characters which is not suitable for UTF-8 encoding.
Currently I am using this code:
new String(java.nio.charset.Charset.forName("UTF-8").encode(myString).array());
But it replaces characters not suitable for UTF-8 with some other obscure characters. Which also does not look good to end user. Could someone please throw some light over any possible solution to tackle this using Java code?
EDIT : For example, exception I got while insertion of 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