0

I have a MySQL database which was created as utf8mb4 (with collation utf8mb4_collate_ci) which I'm accessing via some JSP pages. The JSP pages are all stored as UTF-8, and all include the following tags:

<%@ page contentType="text/html; charset=utf-8" %>

<meta http-equiv="Content-type" content="text/html; charset=utf-8">

Using MySQL Workbench, I can store non-ASCII text in the DB and display it, and in the JSP pages, I can display the stored text correctly. However, when I try to insert new rows containing non-ASCII text from a JSP page they end up being stored as "??????" in the database (and displayed as such whether selected from JSP or from MySQL Workbench). If I display the text I'm inserting as part of the JSP page, it displays correctly in my browser.

The only thing I can think of is that the JSP-to-MySQL network connection somehow uses the wrong encoding, but I'm totally baffled how or why.

Any advice welcomed!

user1636349
  • 458
  • 1
  • 4
  • 21

1 Answers1

0

It was indeed the JSP-to-MySQL encoding that was the problem. Using "show variables" revealed that "character_set_server" was the guilty party, being set to "latin1" instead of "utf8". Madhur Bhaiya's comment helped me to find some links to other pages which advised adding "?characterEncoding=utf8" to the connection string to override the server's default connection encoding. This solved the problem. Thanks, Madhur!

user1636349
  • 458
  • 1
  • 4
  • 21