0

I am currently facing an issue while trying to set a name field in DB using Java. As the names comes from a third party vendor, we get special characters like musical notes or smileys in the name field (e.g. )

Due to the above reason, the DB throws an exception below. org.springframework.jdbc.UncategorizedSQLException: query; uncategorized SQLException for SQL []; SQL state [HY000]; error code [1366]; Incorrect string value: '\xF0\x9F\x8E\xB6' for column 'name'

I want to filter out such characters before setting it in the field.

Please let me know how can I handle the above via regex before setting the values.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563

2 Answers2

0

Before saving to database, you need to check and remove a special character from the name string.

This answer has a code to check and remove a special character.

how-to-remove-special-characters-from-a-string

Minnow
  • 495
  • 4
  • 6
0

Did you tried setting charset as utfmb4 as it supports special characters at db level?

This can be applied, if you intended to allow special characters, else you need to have a mechanism to remove special characters before saving it to database.

For more details, you can check below link

Charset_in_mysql