Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6593987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:45:10+00:00 2026-05-25T17:45:10+00:00

I have a malformed string which may be caused by a bug of MySQL

  • 0

I have a malformed string which may be caused by a bug of MySQL JDBC driver,

The bytes of a sample malformed string (malformed_string.getBytes("UTF-8")) is this:

C3 A4 C2 B8 C2 AD C3 A6 E2 80 93 E2 80 A1  (UTF-8 twice)

which should encoded the following bytes (it’s already UTF-8 encoded, but treat them as ISO-8859-1 enoded)

----- ----- ----- ----- -------- --------
  E4   B8    AD     E6     96       87     (UTF-8)

which should encoded the following Unicode BigEndian bytes

---------------     ---------------------
     4E 2D                65 87            (Unicode BigEndian)

I want to decode the 1st one to the 2nd one, I tried new String(malformed_string.getBytes("UTF-8"), "ISO-8859-1"), but it does not transcode as expected. I’m wondering if there’s something like byte[] encode/decode (byte[] src, String charsetName), or how to achieve the transcode above in java?

Background:

I have a MySQL table which have Chinese column names, when I update such columns with long data, MySQL JDBC driver thrown an exception like this:

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column '中文' at row 1

The column name in the exception is malformed, it should be “中文”, and it must be correctly displayed to user as the following.

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column '中文' at row 1

EDIT

Here’s MySQL statement to demonstrate how the malformed string occured, and how to restore it to correct string

show variables like 'char%';
+--------------------------+--------------------------+
| Variable_name            | Value                    |
+--------------------------+--------------------------+
| character_set_client     | utf8                     |
| character_set_connection | utf8                     |
| character_set_database   | utf8                     |
| character_set_filesystem | binary                   |
| character_set_results    | utf8                     |
| character_set_server     | utf8                     |
| character_set_system     | utf8                     |
| character_sets_dir       | C:\mysql\share\charsets\ |
+--------------------------+--------------------------+

-- encode
select
    hex(convert(convert(unhex('E4B8ADE69687') using UTF8) using ucs2)) as `hex(src in UNICODE)`,
    unhex('E4B8ADE69687') `src in UTF8`,
    'E4B8ADE69687' `hex(src in UTF8)`,
    hex(convert(convert(unhex('E4B8ADE69687') using latin1) using UTF8)) as `hex(src in UTF8->Latin1->UTF8)`;
+---------------------+-------------+------------------+--------------------------------+
| hex(src in UNICODE) | src in UTF8 | hex(src in UTF8) | hex(src in UTF8->Latin1->UTF8) |
+---------------------+-------------+------------------+--------------------------------+
| 4E2D6587            | 中文        | E4B8ADE69687     | C3A4C2B8C2ADC3A6E28093E280A1   |
+---------------------+-------------+------------------+--------------------------------+
1 row in set (0.00 sec)


-- decode
select
    unhex('C3A4C2B8C2ADC3A6E28093E280A1') as `malformed`,
    'C3A4C2B8C2ADC3A6E28093E280A1' as `hex(malformed)`,
    hex(convert(convert(unhex('C3A4C2B8C2ADC3A6E28093E280A1') using utf8) using latin1)) as `hex(malformed->UTF8->Latin1)`,
    convert(convert(convert(convert(unhex('C3A4C2B8C2ADC3A6E28093E280A1') using utf8) using latin1) using binary)using utf8) `malformed->UTF8->Latin1->binary->UTF8`;
+----------------+------------------------------+------------------------------+---------------------------------------+
| malformed      | hex(malformed)               | hex(malformed->UTF8->Latin1) | malformed->UTF8->Latin1->binary->UTF8 |
+----------------+------------------------------+------------------------------+---------------------------------------+
| 中文         | C3A4C2B8C2ADC3A6E28093E280A1 | E4B8ADE69687                 | 中文                                  |
+----------------+------------------------------+------------------------------+---------------------------------------+
1 row in set (0.00 sec)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:45:11+00:00Added an answer on May 25, 2026 at 5:45 pm

    Check out this tutorial: http://download.oracle.com/javase/tutorial/i18n/text/string.html

    The punch line is the way to transcode using only the jdk classes is :

    try {
    byte[] utf8Bytes = original.getBytes("UTF8");
    byte[] defaultBytes = original.getBytes();
    
    String roundTrip = new String(utf8Bytes, "ISO-885-9");
    System.out.println("roundTrip = " + roundTrip);
    System.out.println();
    printBytes(utf8Bytes, "utf8Bytes");
    System.out.println();
    printBytes(defaultBytes, "defaultBytes");
    } catch (UnsupportedEncodingException e) {
     e.printStackTrace();
    }
    

    For a more robust transcoding mechanism I suggest you check out ICU>

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large malformed test HTML document which I need to get the
Possible Duplicate: Decode HTML entities in Python string? I have a malformed string in
I have created an aspx page which dynamicaly creates an xml string and posts
I have a String: Sun May 15 00:00:00 IST 2011 Now if I want
Does anyone have a good way of finding if a string contains malformed XHTML
I have a malformed tab delimited csv file Name AA BB CC AA BB
I have a malformed page to scrape, and have had a hard time getting
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have multiple threads which are serializing my 'Data' objects to files. The filename
I have a email multi-part message which I am using to send failed message

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.