0

I am trying to save the emojis that are being passed in the below texts message and description as below

String description="3⃣5⃣3⃣‼〽➗➗♋♍♋♍⬅⬆⬅⬅"

String message= "Hi How are you "

When I encode the description using below code, It encodes fine but the description column in database is shown as

Expert%2Chi+%F0%9F%91%8B+was+your+

and message as Hi+How+are+you

public static String encodeStringUrl(String url) {
        String encodedUrl =null;
    try {
        encodedUrl = URLEncoder.encode(url, "UTF-8");
    } catch (Exception e) {
        return encodedUrl;
    }
    return encodedUrl;
}

I would like to know if there is any way to store the message and description in Mysql tables with the same description and message with emoticons as it will give us a chance to search properly with the String for example

Now the message "Hi How are you"(it is normal text but it can also have emojis that's why encoded) is saved as Hi+How+are+you

When I try to fetch data from db basing on message column as below I will get null data because the value is Hi+How+are+you

   select * from employee where message="Hi How are you" 

I have also made changes to the table

    ALTER TABLE Employee CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
Sawyer
  • 423
  • 1
  • 7
  • 23
  • What is the encoding of your db / table? UTF-8 is _not_ it in MySQL. See [this answer](https://stackoverflow.com/a/35189650/223424). – 9000 Jan 23 '18 at 17:16
  • 1
    You need `utf8mb4` to store these, not just `utf8`. – tadman Jan 23 '18 at 17:17
  • Don't use `URLEncoder.encode()` on the data before you store it in the database. Some characters aren't allowed in URL's and will either be swapped according to some convention or attempt to represent as a string of byte codes. That's what the encoding is for, after all. – Jerry Jan 24 '18 at 00:29

0 Answers0