0

My problem is, I can't insert correctly accented characters (á é í ó ú ñ) in my DB.

This is my output console:

Picture 1

As you can see the original text of the column grupo is Cómputo integrál.

The same happens in my output web browser:

Picture 2

This is my servlet code:

//Save the input form and search immediately
tx.begin();
Salon get = (Salon) session.get(salon.getClass(), 1);
tx.commit();

request.setCharacterEncoding("utf8");//Línea para que se ingresen de forma correcta los caracteres.
response.setContentType("text/html;charset=ISO-8859-1");

try (PrintWriter out = response.getWriter())
{
    out.println("Salida de texto: " + get.getGrupo());
}

This is my meta html code:

<meta charset="UTF-8">

And my DB is configured with the collation utf8 - utf8_spanish_ci

What I can do to save, insert, show and update correctly?

vivekpansara
  • 895
  • 1
  • 6
  • 14
Chomboreco
  • 87
  • 9
  • 1
    Why have you set the content type to ISO-8859-1 if you're actually using UTF-8? See http://codeblog.jonskeet.uk/2014/01/20/diagnosing-issues-with-reversible-data-transformations/ for details about what you should do to diagnose the problem. – Jon Skeet Jun 05 '15 at 15:22
  • The same applies if I change the content type to utf8. – Chomboreco Jun 05 '15 at 15:28
  • Additionally, "As you can see the original text of the column grupo is Cómputo integrál" - no, we can't see that at all. We can only see the broken text. So we don't know whether the problem is *reading* it or *writing* it. – Jon Skeet Jun 05 '15 at 15:29
  • Voting to close: Mojibake. See [duplicate](http://stackoverflow.com/questions/29881114/how-to-avoid-junk-garbage-characters-while-reading-data-from-multiple-languages/29907185#29907185) for discussion and solution, including how to recover the data via a pair of `ALTER TABLEs`. – Rick James Jun 26 '15 at 01:02

1 Answers1

0

Try adding the following in the URL of the connection to the database:

jdbc:mysql://localhost/mydb?useUnicode=yes&characterEncoding=UTF-8

Paul Vargas
  • 41,222
  • 15
  • 102
  • 148