2

I have a form but every time I submit with Korean characters, it shows up in my phpmyadmin database as question marks or is extremely convoluted. I want to be able to submit entries in my MySQL database table using both latin and asian characters, also I'm using java in Eclipse.

I have already done the following:

  • added this in my jsp files

    contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"

  • modified Connector tag in my server.xml file to have URIEncoding="UTF-8"

  • modified URL of connection

    conn = DriverManager.getConnection("jdbc:mysql://localhost/login?useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8", "root", "");

  • added this is in my doPost method in Servlet that handles the form data

    response.setContentType("text/html; charset=UTF-8");

and the following screenshots below. Many thanks in advance for any help.

enter image description here

enter image description here

enter image description here

bananas
  • 1,176
  • 2
  • 19
  • 39
episkeyyy
  • 109
  • 11

2 Answers2

3

When trying to use utf8/utf8mb4, if you see Question Marks (regular ones, not black diamonds),

  • The bytes to be stored are not encoded as utf8. Fix this.
  • The column in the database is CHARACTER SET utf8 (or utf8mb4). Fix this.
  • Also, check that the connection during reading is utf8.

When trying to use utf8/utf8mb4, if you see Black Diamonds with question marks, one of these cases exists:

Case 1 (original bytes were not utf8):

  • The bytes to be stored are not encoded as utf8. Fix this.
  • The connection (or SET NAMES) for the INSERT and the SELECT were not utf8/utf8mb4. Fix this.
  • Also, check that the column in the database is CHARACTER SET utf8 (or utf8mb4).

Case 2 (original bytes were utf8):

  • The connection (or SET NAMES) for the SELECT was not utf8/utf8mb4. Fix this.
  • Also, check that the column in the database is CHARACTER SET utf8 (or utf8mb4).

Black diamonds occur only when the browser is set to <meta charset=UTF-8>

Note: euckr is not the same as utf8. It can be handled, but different steps are needed.

Rick James
  • 135,179
  • 13
  • 127
  • 222
  • thank you. this helped guide me in focusing on what the problem could be. :) – episkeyyy Jul 04 '16 at 23:29
  • Even more complete is the Q&A that I derived from it: https://stackoverflow.com/questions/38363566/trouble-with-utf-8-characters-what-i-see-is-not-what-i-stored – Rick James Aug 20 '18 at 14:12
2

I recommend you take everything out of the equation except the database to ensure the problem really is with the database. First examine the values in hexadecimal:

SELECT HEX(column_name) FROM table_name

If you see "3F" where you are seeing "?", then there is most likely a problem with the data coming from your web application (more help here in section A.11.2 like using SET NAMES and changing the MySQL INI file). You should also try manually inserting hexadecimal into the database table and selecting it back both normally and as hexadecimal to ensure the data is going in and out correctly.

If you still suspect a database problem, ensure your table is encoding the character set (i.e. DEFAULT CHARSET) correctly, for example (or other examples):

SHOW CREATE TABLE table_name
Community
  • 1
  • 1
  • thank you. my problem was with the connection not encoding the data, so it was indeed a problem with my web application. I fixed it with this http://stackoverflow.com/a/11064894/6392216 – episkeyyy Jul 04 '16 at 23:27