0

My Sql-Database uses utf8_bin, which is limited to 3-Byte-Characters. Im using a pre "5.1.46" Mysql connector.

On this site: https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-charsets.html, it is stated that using the "characterEncoding=utf-8" parameter, means that it uses utf8mb3. Which would be correct in my case. The problem is, that the application will throw a Mysql-Exception when it tries to write a 4-Byte-Character:

for example:
java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x81 \xC4...'

Furthermore, if I dont specify the characterEncoding-parameter at all, it will default to some other charset. The problem here is, that a lot of characters that I need to be able to write into the DB will just be replaced by a "?". Like "ğ" for example.

So far, the only Solution I see to this problem is just removing all 4-Byte characters from a String, before I write it into the Database, since changing the charset of the Database iself is not an option unfortunatley

But I was wondering if im missing something here. Is there better way to do this?

Thanks a lot

BärenHund1
  • 133
  • 1
  • 9
  • See documentation https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-usagenotes-troubleshooting.html related to using of 4-byte UTF8 (utf8mb4). So, in the URL of connection you must use characterEncoding property to achieve that. – Mihai8 Apr 12 '19 at 09:18
  • What version of MySQL? utf8mb4_bin is the corresponding Collation for utf8mb4. – Rick James May 12 '19 at 15:35
  • `ğ` is hex `C49F` in both utf8 and utf8mb4. So the `?` is a _different problem_. See "question mark" in https://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored – Rick James May 12 '19 at 15:38

0 Answers0